当前位置:网站首页>[harmonyos] [ark UI] how does harmonyos ETS language realize double clicking the return key to exit
[harmonyos] [ark UI] how does harmonyos ETS language realize double clicking the return key to exit
2022-07-22 14:48:00 【Huawei Developer Forum】
Reference material
【Harmony OS】【ARK UI】Date Basic operation
Custom component lifecycle callback function
Code runs
Ideas :
Define a global variable , Judge the difference between the click time and the last click time , If more than 2 Second prompt ‘ Press again to exit the program ’ word , Less than 2 Seconds to exit the application , The code is as follows
import prompt from '@system.prompt';
import app from '@system.app'
@Entry
@Component
struct Index {
//todo Define global variables
@State exitTime: number= 0;
private onBackPress() {
this.ExitApp();
return true;
}
public ExitApp() {
//todo Judge the difference between the click time and the last click time , If more than 5 Second prompt ‘ Press again to exit the program ’ word
if ((new Date().getTime() - this.exitTime) > 5000) {
prompt.showToast({
message: ' Press again to exit the program ',
duration: 2000,
});
this.exitTime = new Date().getTime();
} else {
//todo Less than 5 Seconds to exit the application
app.terminate();
}
}
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(' Double click to return to app sign out ')
.fontSize(40)
.height(200)
.width("100%")
.textAlign(TextAlign.Center)
.fontWeight(FontWeight.Bold)
}
.width('100%')
.height('100%')
}
}
Running effect
For more technical articles , Welcome to visit https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh
边栏推荐
- 【电路设计】充电台灯电路拆解
- Matlab基本语法(二)
- 2022 low voltage electrician examination simulated 100 questions and simulated examination
- Practice of online problem feedback module (10): realize image preview function
- Wechat applet development process
- 【HarmonyOS】【ARK UI】HarmonyOS ets语言怎么实现双击返回键退出
- Using Siemens low code to realize the agility of enterprise quality management process
- 【多线程】实现线程到底只有一种方式还是四种方式
- [multithreading] is there only one way to implement threads or four ways
- [server data recovery] data recovery case of a Huawei server raid6
猜你喜欢
DevEco Studio3.0下载失败,提示An unknown error occurred
Mysql語句的RegExp的用法與案例
【AGC】构建服务1-云函数示例
【HMS core】【Analytics Kit】【FAQ】如何解决华为分析付费分析中付款金额显示为0的问题?
【Harmony OS】【ARK UI】【Demo】加载动画实现
winodos下配置laradock
Practice of online problem feedback module (10): realize image preview function
检查SPF记录 宽泛的IP范围会破坏电子邮件的安全性
【服务器数据恢复】华为某型号服务器raid6数据恢复案例
Mysql语句的RegExp的用法与案例
随机推荐
【电路设计】充电台灯电路拆解
Internet Download Manager老牌下载器最佳的电脑下载工具
【HMS Core】【FAQ】运动健康、音频编辑、华为帐号服务 典型问题合集7
【Pingtunnel工具教程】利用ICMP隧道技术进行ICMP封装穿透防火墙
初阶数据结构 —— 顺序表和链表(带头双向循环链表)的优缺点 + CPU缓存的知识。
LeetCode 215:数组中的第K个最大元素
[cicadaplayer] the problem that the release cannot debug at breakpoints
力扣(LeetCode)202. 快乐数(2022.07.21)
[multithreading] the difference between parallelism and concurrency
MySql集群之多实例数据库搭建(二)
三星提出XFormer | 超越MobileViT、DeiT、MobileNet等模型
Deep learning neural network cyclic neural network (I): RNN (recurrent neural network; 1990)
在线问题反馈模块实战(十):实现图片预览功能
Cordove Youmeng plug-in ++ push and statistics functions
中年危机,关于未来的一些思考
【AGC】增长服务2-应用内消息示例
【开发者必看】【push kit】推送服务典型问题合集3
这一次,彻底梳理各种布局问题
QProcess类
2022 crane driver (bridge crane only) examination question bank and answers