Android classic exit method, android classic exit
Android classic perfect exit method: creates an Activity management object in singleton mode. This object has an Activity container (which can be processed by yourself and used in sort list) it stores every newly opened Activity, which is easy to understand and operate!
AppUtils class (stores every Activity and closes all activities)
/** To change this template, choose Tools | Templates * and open the template in the editor. */package com. cpic. jscx. android. utils; import android. app. activity; import android. app. application; import java. util. using list; import java. util. list;/***** @ author user he asked hovertree.com */public class AppUtils extends Application {private List <Activity> activityList = new extenlist <Activity> (); private static AppUtils instance; private AppUtils () {}// obtain the unique public static AppUtils getInstance () {if (null = instance) of the app instance in singleton Mode) {instance = new AppUtils ();} return instance;} // Add the Activity to the container and ask hovertree.com public void addActivity (Activity activity) {activityList. add (activity);} // traverse all activities and finish public void exit () {for (Activity: activityList) {activity. finish ();} System. exit (0 );}}
Add the Activity to the AppUtils object instance container in the onCreate method of each Activity
AppUtils. getInstance (). addActivity (this );
Public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); AppUtils. getInstance (). addActivity (this); setContentView (R. layout. main); findViews ();}/* He asked hovertree.com */
Recommended: http://www.cnblogs.com/roucheng/p/androidjiqiao.html