Activity declaration cycle
Method 1
We know that the window class of Android provides a historical stack, and we can implement it skillfully through the stack principle. Here we add the intent icon directly to window a when window a opens window B. flag_activity_clear_top. When B is enabled, all activities in the process space are cleared.
Use the followingCodeCall window B
Java code
Intent intent = new intent ();
Intent. setclass (android123.this, cwj. Class );
Intent. setflags (intent. flag_activity_clear_top); // pay attention to the flag settings of the row.
Startactivity (intent)
Method 2:
Write in the call exit Method
Myapplication. getinstance (). Exit ();
Public class myapplication extends application {
Private list <activity> activitylist = new shortlist <activity> ();
Private Static myapplication instance;
Private myapplication (){
}
// Obtain the unique myapplication instance in singleton Mode
Public static myapplication getinstance (){
If (null = instance ){
Instance = new myapplication ();
}
Return instance;
}
// Add the activity to the container
Public void addactivity (activity) {
activitylist. add (activity);
}
// traverse all the activities and finish
/*
* in each activity in the oncreate method, add the activity to the container of the myapplication object instance
* myapplication. getinstance (). addactivity (this );
* call the exit method when you want to end all activities.
*
* myapplication. getinstance (). exit ();
*/
Public void exit () {
For (activity: activitylist ){
Activity. Finish ();
}
System. Exit (0 );
}