Android implements the function of double-click exit

Double click the back button of Android to exit the current app function

The basic idea of realizing this function is,

1. Monitor the back button and compare the back interval between two times. If it is less than two seconds, start and exit

2. Exit the current app

I choose to set listening in baseactivity in the base class. The code is as follows:

In exiting the current app, reference open source China and encapsulate the activity stack

Example code:

The idea is to manage each time an activity is pushed into the activity stack

When exiting, traverse the stack and finish one by one

I hope this article will be helpful to your Android program design.

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