Customize a class that inherits from application. Used to record the activity that was opened.
Call Exitapplication.newinstance (). Addactivity (this) in the OnCreate method of each activity class, and add the activity class to the list.
Call Exitapplication.newinstance () at exit. exit (); loop execution Finish ();
public class Exitapplication extends application {
private static list<activity> aclist = new linkedlist<activity> ();
private static Exitapplication instance = NULL;
Private Exitapplication () {}
Single-Case mode
public static Exitapplication newinstance () {
if (null==instance) {
Instance = new Exitapplication ();
}
return instance;
}
public void Addactivity (Activity a) {
Aclist.add (a);
}
public static void Exit () {
for (Activity activity:aclist) {
Activity.finish ();
}
System.exit (0);
}
}
Android completely quits the app