Put the activity instance in a linear container in oncreate (). When you exit (activity) List. GERT (I). finsh ();
There are also obvious problems...
The reference of the activity is saved, whether it will be involved, and the memory is recycled .... (You have to use the following method for strong reference .)
Package COM. mystore. customer. activity; import Java. io. printwriter; import Java. io. stringwriter; import Java. io. writer; import Java. lang. thread. uncaughtexceptionhandler; import Java. util. using list; import Java. util. list; import mylog. log; import android. app. activity; import android. app. application; import android. content. PM. packagemanager. namenotfoundexception; import COM. mystore. customer. activity. lookfor. loo Kforcustomeractivity; import COM. mystore. customer. activity. more. moremessageactivity; import COM. mystore. customer. activity. ramble. hotstoreactivity; import COM. mystore. customer. activity. search. searchmainactivity; public class customerapplication extends application {Private Static final string tag = "customerapplication"; Private Static application; public static string version = "1.1"; Public Static long exit_timeout = 2500l; // Add activity container, used to exit app private list <activity> activitylist = new sort list <activity> (); Private Static customerapplication instance; // obtain the unique exitapplication instance public static customerapplication getinstance () {If (null = instance) {instance = new customerapplication ();} return instance;} in singleton Mode ;} // Add the activity to the container public void addactivity (activity activi Ty) {activitylist. add (activity);} // traverse all activities and finishpublic void exit () {for (activity: activitylist) {activity. finish ();} system. exit (0);} public void poptomaintab () {for (INT I = activitylist. size ()-1; I> 0; I --) {activity = activitylist. get (I); If (activity! = NULL) {If (hotstoreactivity. class ). equals (activity. getclass () | (mainactivity. class ). equals (activity. getclass () | (searchmainactivity. class ). equals (activity. getclass () | (moremessageactivity. class ). equals (activity. getclass () | (lookforcustomeractivity. class ). equals (activity. getclass () {// jump out of loop break;} else {activity. finish () ;}}@ overridepublic void oncreate () {super. oncreate (); thread. partition (new partition () {public void uncaughtexception (thread, throwable) {final writer result = new stringwriter (); Final printwriter = new printwriter (result); throwable. printstacktrace (printwriter); string strstacktrace = result. tostring (); printwriter. close (); log. E ("", "================================"); log. E ("", "force close occur, thread is:" + thread + "throwable:" + throwable); log. E ("", "stacktrace" + strstacktrace); log. E ("", "================================ ");}}); application = This; try {version = This. getpackagemanager (). getpackageinfo (this. getpackagename (), 0 ). versionname;} catch (namenotfoundexception e) {e. printstacktrace () ;}} public static application getapplication () {return application ;}}