In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article Xiaobian introduces in detail "how to double-click the back key in Android to exit the application" with detailed contents, clear steps and proper handling of the details. I hope that this article "how to double-click the back key in Android to exit the application" can help you solve your doubts.
The principle of implementation:
The principle of double-clicking to exit the program is nothing more than setting an exit flag (asking whether to exit). If you change this logo (confirm exit), you will exit immediately when you click again, and if you do not exit within a specified period of time, then delay to reset the flag (do not exit).
Delay reset:
Using Java API provides the Timer class, which can perform scheduled tasks. Using Timer, it is possible to delay reset the identity.
The schedule () method of the Timer object requires a TimerTask object and a length of time (milliseconds) as parameters. The TimerTask object needs to override its run () method, and when Timer performs a deferred task, it executes the run () method of TimerTask.
Exit code
(added to Activity)
Private boolean quit = false; / / set the exit flag @ Override public void onBackPressed () {if (quit = = false) {/ / ask the exit program Toast.makeText (this, "press exit program again", Toast.LENGTH_SHORT). Show (); new Timer (true) .schedule (new TimerTask () {/ / start scheduled task @ Override public void run () {quit = false) / / reset the exit identity}, 2000); / / run the run () method quit = true;} else {/ / confirm the exit program super.onBackPressed (); finish () }} read here, this article "how to double-click the back key in Android to exit the application" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.