PackageLiu.basedemo;Importandroid.app.Activity;Importandroid.app.Application;Importjava.lang.ref.WeakReference;ImportJava.util.Stack;/*** MyApplication Application Basic * Created by Liu Nan on 2016/7/28 0028.21:45*/ Public classMyApplicationextendsApplication {Private StaticMyApplication INSTANCE; /*** Task Stack*/Stack<WeakReference<Activity>> Mtasks =NewStack<weakreference<activity>>(); @Override Public voidonCreate () {Super. OnCreate (); INSTANCE= This; } Public StaticMyApplication getinstance () {returnINSTANCE; } /*** Add an activity * *@paramTask*/ Public voidPushtask (weakreference<activity>Task) {Mtasks.push (Task); } /*** Remove the specified activity * *@paramTask*/ Public voidRemovetask (weakreference<activity>Task) {Mtasks.remove (Task); } /*** Move the taskactivity at the specified position * *@parampoistion*/ Public voidRemoveindextask (intpoistion) { if(Mtasks.size () >poistion) {Mtasks.remove (poistion); } } /*** Remove all activity*/ Public voidRemovealltask () { for(weakreference<activity>task:mtasks) { /*** Judging if there's no end, no ending.*/ if(!task.get (). isfinishing ()) { //EndTask.get (). Finish (); } } } /*** Remove from top*/ Public voidRemovetop () {intStart = 1; intEnd =mtasks.size (); for(inti = end-1; I >= start; i--) { /*** Judging if there's no end, no ending.*/ if(!Mtasks.get (i). get (). Isfinishing ()) {Mtasks.get (i). Get (). Finish (); } } }}
Android in MyApplication