Hello everyone, today brings the dual-push-out program implementation method, I know, there are many on the internet on the dual-exit program implementation of the method, so, hear of course is to bring a different double-exit implementation method.
First brought is about onkeydown and onkeypress These two methods of description, the following is reproduced, I will directly cut a picture for you to see, URL http://blog.csdn.net/mingxunzh/article/details/5497948
Up to now, the android4.0+ system accounted for 99% of the market, so, now also use the onkeydown () method to achieve double-click return function is simply out of the out
Now we can implement the above mentioned double-click return function through the ONBACKPRESSD () method .
The project I used to create the Android studio is exactly what the drawlayout, which is the side-slip interface provided by Android Studio,
The onbackpressed () method is replicated in the main interface code of the project, and the approximate meaning is to detect if the drawerlayout is open, and execute the Closexx method, The alternative is to call the Onbackpressed method again (that is, drawerlayout shuts down and the program does nothing).
The double-click return function that we want to implement is to be called only when the drawerlayout is turned off, so the statement after the else is modified directly .
The exit () method code is as follows:
Public void exit () { if ((System.currenttimemillis ()-exittime >){ "Press and exit the program again", C8/>toast.length_short). Show (); = System.currenttimemillis (); Else { OnDestroy (); } }
System.exit (0); To completely exit the program
PS: Here by the way, I have a project in the opening animation activity, just joined the dual-exit program This feature, and can not achieve a full exit, double-exit after the return to the opening animation activity, after repeated review of the code, found to be The opening animation does not have a finish () method when jumping activity , adding this method is possible
Android Dual Exit program implementation (with side-slip interface)