below is the end of the entire application used in my project. exiting all activities includes services:
Import Java. util. using list; import Java. util. list; import android. app. activity; import android. app. application; public class myapplication extends application {private list <activity> activitylist = new extenlist <activity> (); Private Static myapplication instance; private myapplication () {}// obtain the unique myapplication instance public static myapplication getinstance () {If (null = instance) {instance = new myapplication ();} return instance;} in singleton Mode ;} // Add the activity to the container public void addactivity (activity) {activitylist. add (activity) ;}// traverse all activities and finishpublic void exit () {New mycommondialog ("saving data .. ") {@ overrideprotected string donouiopt () {// todo auto-generated method stubfor (activity: activitylist) {activity. finish ();} return Super. donouiopt () ;}@ overrideprotected void Doback (string success) {// todo auto-generated method stubsystem. exit (0); super. doback (SUCCESS );}};}}
In the exit () method, you can directly use: for (activity: activitylist) {activity. Finish ();} return Super. donouiopt (); system. Exit (0 );
Mycommondialog is a custom prompt class, which can be removed directly.