Android-exiting the application

Source: Internet
Author: User

On Android, when you click the Back button, the Finish method (or the Destroy method, not very clear) is called by default so you can exit the current activity. Note that this is the current activity, not the application, because if the program has multiple activity, when you click Back in the nth activity, it will only end the current one and return to the first N-1 activity.

So you can use the following method if you want to exit the program directly, rather than step-by-step forward. The class that defines a singleton pattern, when all activity is created, is oncreate when the activity object is added to a list of this class, and then exits, one by one, the activity in the list is ended, So that when the last activity ends, it exits the program. First, define a class that implements the singleton pattern: There are three methods to invoke in this class, one to create an instance object of this class getinstance, one to add activity to the list addactivity, and one to iterate through, End all activity's exit. Add words to all of the activity's OnCreate methods:

Then click Exit to call this:

This method is used in all cases, but it is to define the class itself, feeling less efficient than the system's turn: http://blog.sina.com.cn/s/blog_703074da0101baxg.html

Android-exiting the application

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.