Use stackmanager to manage the Android app activity by yourself
Directly Add code
Package COM. example. test; import Java. util. hashmap; import Java. util. iterator; import Java. util. map; import Java. util. stack; import android. app. activity; public class stackmanager {// stack manager stackmanager instance Private Static stackmanager instance; // stack is a type of data structure (LIFO) that stores stacks of a series of objects. You can perform pop and push operations on the stack, even if it is a null object, and the stack has no size to display the stack <activity> activitystack = new stack <activity> (); map <string, activity> mapstack = new hashmap <string, activity> ();/*** obtain the instance in singleton mode * @ return */Public synchronized static stackmanager getinstance () {If (instance = NULL) instance = new stackmanager (); Return instance ;} /*** add activity to stack to prepare for exit ** @ Param activity */Public void pushtostack (Activity Activity) {If (activity! = NULL) activitystack. add (activity);}/*** clear all the activities in the stack */Public void popallforexit () {for (Activity E: activitystack) E. finish (); activitystack. clear ();}/*** add activity to the stack to prepare for the navigation area ** @ Param key * @ Param activity */Public void pushtomapstack (string key, activity) {If (! Mapstack. containskey (key) mapstack. put (Key, activity);} public void popallforstartactivity (string key) {iterator <string> iterator = mapstack. keyset (). iterator (); While (iterator. hasnext () {string K = iterator. next (); If (! K. equals (key) {mapstack. get (k ). finish (); mapstack. remove (k); iterator = mapstack. keyset (). iterator ();}}}}
If the project needs to be added, it is OK.