According to the activity's declaration cycle
Method 1
We know that the Android window class provides a history stack, which we can skillfully implement using the stack principle, where we add the flag intent.flag_activity_clear_top directly to the Intent when opening the b window in a window. When you turn on B, all activity for that process space will be cleared.
In the a window, use the following code to invoke the b window
Java code
Intent Intent = new Intent ();
Intent.setclass (Android123.this, Cwj.class);
Intent.setflags (Intent.flag_activity_clear_top); Note the flag setting of the bank
StartActivity (Intent)
Method 2:
In the call exit method, write the
Myapplication.getinstance (). exit ();
public class MyApplication extends application {
Private list<activity> activitylist = new linkedlist<activity> ();
private static MyApplication instance;
Private MyApplication () {
}
Get a unique MyApplication instance in singleton mode
public static MyApplication getinstance () {
if (null = = Instance) {
Instance = new MyApplication ();
}
return instance;
}
Adding activity to the container
public void addactivity (activity activity) {
Activitylist.add (activity);
}
Traverse all activity and finish
/*
* Add the activity to the MyApplication object instance container in each activity's OnCreate method
*
* Myapplication.getinstance (). addactivity (this);
*
* Call the Exit method when you need to end all activity
*
* Myapplication.getinstance (). exit ();
*/
public void exit () {
for (Activity activity:activitylist) {
Activity.finish ();
}
System.exit (0);
}
Learn from Android-how to turn off all activity