Implementation method of Android double clicking back key to exit application
Implementation method of Android double clicking back key to exit application
Implementation principle:
The principle of double clicking to exit the program is nothing more than setting an exit sign (asking whether to exit). If this sign is changed (confirm exit), click again to exit immediately. If there is no exit within the specified time, delay to reset this sign (do not exit).
Delay reset:
The timer class is provided using the Java API, which can perform scheduled tasks. With timer, the identification can be delayed reset.
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. When timer executes a delayed task, it will execute the run () method of TimerTask.
Exit code
(added in activity)
If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!