Android Classic Perfect Exit method, using singleton mode to create an activity management object, which has an activity container (specifically to implement its own processing, using LinkedList, etc.) is dedicated to storing the newly opened each activity, and easy to understand, Easy to operate, very good!
Apputils Class (stores each activity and implements the action to close all activity)
/** To change this template, choose Tools | Templates * and open the template in the editor. */ Packagecom.cpic.jscx.android.utils; Importandroid.app.Activity; Importandroid.app.Application; Importjava.util.LinkedList; Importjava.util.List; /** * * @authoruser how to ask hovertree.com*/ Public classApputilsextendsapplication{PrivateList<activity> activitylist =NewLinkedlist<activity>(); Private StaticApputils instance; Privateapputils () {}//get a unique instance of an app in singleton mode Public Staticapputils getinstance () {if(NULL==instance) {Instance=Newapputils (); } returninstance; } //add activity to container why ask Hovertree.com Public voidaddactivity (activity activity) {Activitylist.add (activity); } //traverse all activity and finish Public voidexit () { for(Activity activity:activitylist) {activity.finish (); } system.exit (0); } }
Add the activity to the Apputils object instance container in each activity's OnCreate method
Apputils.getinstance (). addactivity (this);
Public void onCreate (Bundle savedinstancestate) { super. OnCreate (savedinstancestate); Apputils.getinstance (). addactivity (this); Setcontentview (r.layout.main); Findviews (); } /* */
Recommendation: http://www.cnblogs.com/roucheng/p/androidjiqiao.html
Android Classic Perfect Exit method