Android Dual Exit program implementation (with side-slip interface)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.