Android back click twice to exit the application details and implementation method summary
Idea: capturing user keys in Android is in the onkeydown method. You only need to judge whether the user keys are keycode_ Back is the back key, and the rest is to judge the time interval between two clicks of the back key
The first implementation
In the exit method, the value of isexit will be judged first. If it is false, it will be set to true. At the same time, a prompt will pop up, and a message will be sent out after 2000 milliseconds (2 seconds) to restore this value to false in the handler. If you press the back key again within 2 seconds of the message sending interval, the exit method will be executed again. At this time, if the value of isexit is true, the exit method will be executed.
The second implementation
Judge whether the time difference between the user's two keys is within an expected value. If yes, exit directly. If not, prompt the user to press the back key again to exit.
Thank you for reading, hope to help you, thank you for your support to this site!