There are a number of ways to turn off all activity when exiting the app on Android, such as sending a global broadcast, killing the current PID directly 、、、 but if we do a function that is an SDK then the situation is different. After the project went live, we decided to manage our activity by customizing the stack.
First of all talk about this deceptive broadcast, because we are sending out of order broadcast, do not know that the activity will be received first, this led to a serious problem = = after receiving the broadcast activity will redraw and our demand is not want activity to be re-created a lot of bugs Second, we think of the direct kill PID, but the tragedy is that our SDK and app with the same application, kill the PID after application directly quit ... In the end, manually manage the activity in the SDK with stack itself.
This way everyone is using, I will not say more, directly read code
Define an activity management stack
Package Com.example.tasktest;import Java.util.stack;import android.app.activity;/** * *〈 A Word function description 〉<br> *〈 function Details Activity Management Stack * * @see [related Classes/methods] (optional) * @since [Product/module version] (optional) */public class Actiivtystack {private static Stack<acti vity> mactivitystack = new stack<activity> (); private static Actiivtystack instance = new Actiivtystack (); Private Actiivtystack () {} public static Actiivtystack Getscreenmanager () {return instance; }//pops up the current Activity and destroys the public void popactivity (activity activity) {if (activity! = NULL) {activity . Finish (); Mactivitystack.remove (activity); activity = NULL; }}//pushes the current Activity into the stack public void pushactivity (activity activity) {Mactivitystack.add (activity); }//exit the stack all activity public void clearallactivity () {while (!mactivitystack.isempty ()) {activity Activity = Mactivitystack.pop (); if (activity! = NULL) { Activity.finish (); } } }}Defining the parent class for activity in the SDK
Package Com.example.tasktest;import Android.os.bundle;import Android.support.v4.app.fragmentactivity;import Android.util.log;public abstract class Baseactivity extends Fragmentactivity { @Override protected void OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); LOG.I ("Jone", "base OnCreate"); Each time you join Stack actiivtystack.getscreenmanager (). pushactivity (this); } @Override protected void OnDestroy () { log.i ("Jone", "base Destory"); Eject stack actiivtystack.getscreenmanager () when exiting. Popactivity (this); Super.ondestroy (); }}
Resource URL http://download.csdn.net/download/yaya_soft/8589337
Turn off all activity methods in Android