The Activity Management class, which manages all actvity, provides the ability to add activity to the stack, end a specific activity, end all activity, and so on, has the necessary features in project development: Exit function, and exit function usually exits the application in the project. Sign out of the two cases, here for both of these situations are implemented, here to do a record, for later review
PackageCom.centrvideo.parkapp.util;Importjava.util.concurrent.CopyOnWriteArrayList;Importandroid.app.Activity;ImportAndroid.app.ActivityManager;ImportAndroid.content.Context;Importcom.centrvideo.parkapp.activity.LoginActivity;/*** Activity management class for managing activity, program Exit * @ClassName: AppManager * @Description: *@authorXiaoxiao * @date Modify by 2015-8-17 pm 1:33:27 **/ Public classAppManager {Private StaticCopyonwritearraylist<activity>Mactivitystack; Private StaticAppManager Mappmanager; PrivateAppManager () {}/*** Single Instance*/ Public StaticAppManager getinstance () {if(Mappmanager = =NULL) {Mappmanager=NewAppManager (); } returnMappmanager; } /*** Add activity to Stack*/ Public voidaddactivity (activity activity) {if(Mactivitystack = =NULL) {Mactivitystack=NewCopyonwritearraylist<activity>(); } mactivitystack.add (activity); } /*** End the specified activity*/ Public voidkillactivity (activity activity) {Try { if(Activity! =NULL) {mactivitystack.remove (activity); Activity.finish (); Activity=NULL; } } Catch(Exception e) {e.printstacktrace (); } } /*** End activity for specified class name*/ Public voidKillactivity (class<?>CLS) { for(Activity activity:mactivitystack) {if(Activity.getclass (). Equals (CLS)) {killactivity (activity); } } } /*** End All activity*/ Public voidkillallactivity () { for(inti = 0, size = mactivitystack.size (); i < size; i++) { if(NULL!=Mactivitystack.get (i)) {Mactivitystack.get (i). Finish (); }} mactivitystack.clear (); } /*** End all activity except login*/ Public voidKillallactivitynologin () { for(inti = 0, size = mactivitystack.size (); i < size; i++) { if(NULL!=Mactivitystack.get (i)) { if(Mactivitystack.get (i). GetClass ()!=loginactivity.class) {mactivitystack.get (i). Finish (); }}} mactivitystack.clear (); } /*** Exit Application*/@SuppressWarnings ("Deprecation") Public voidAppExit (Context context) {Try{killallactivity (); Activitymanager Activitymgr=(Activitymanager) context. Getsystemservice (Context.activity_service); Activitymgr.restartpackage (Context.getpackagename ()); System.exit (0); } Catch(Exception e) {e.printstacktrace (); } }}
From for notes (Wiz)
List of attachments
Activity management class, program Exit Tool class