Learn a lot on the internet and how the Android activity exits. Many methods are not good, try a variety of methods, the following method is my favorite, simple and easy to understand.
uses a single case pattern to create an activity management object, which has one activity container (implementing itself, using LinkedList, and so on) dedicated to storing each of the newly opened operations, and easy to understand, easy to operate, very good!
MyApplication Class (stores each activity, and implements the operation to close all of the actions
Copy Code code as follows:
public class MyApplication extends application {
Private list<activity> activitylist = new linkedlist<activity> ();
private static MyApplication instance;
Private MyApplication ()
{
}
To get a unique MyApplication instance in a single case pattern
public static MyApplication getinstance ()
{
if (null = = instance)
{
Instance = new MyApplication ();
}
return instance;
}
Add an activity to the container
public void addactivity (activity activity)
{
Activitylist.add (activity);
}
Traverse all activity and finish
public void exit ()
{
For (activity activity:activitylist)
{
Activity.finish ();
}
System.exit (0);
}
}
adds the activity to the MyApplication object instance container in the OnCreate method in each activity
Copy Code code as follows:
Myapplication.getinstance (). addactivity (this);