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