Android double click the return key to exit the program

Android double click the return key to exit the program

Let's talk about LZ first, as follows:

1. The first method is to judge whether to exit the program according to the time interval between two clicks by the user;

2. The second is to use the timer in Android. In fact, they are similar

The train of thought is, what's the next step??? The user's click will certainly trigger the corresponding event. Let's first look at the functions of the following two events...

Activity.onKeyDown();

When a key is pressed, it will be triggered, but it will not be processed by any view in the activity.

Keycode is pressed by default_ The back key will return to the previous activity.

Activity.onKeyUp():

When a key is pressed and released, it will be triggered, but it will not be processed by any view in the activity.

By default, no operation is performed, but simply give a false as the return value.

Next, use the above two methods to kill the roadblock~

One Way:onKeyUp()

Two Way:onKeyDown()

Three Way:Timer

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
分享
二维码
< <上一篇
下一篇>>