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!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>