For beginners, Android app exit is sometimes a headache, the following simple summary of several common exit methods:
Big direction, exit thinking is nothing more than the program all the activity to destroy, the idea is clear, see Make what recruit ~
1. Manufacturing throw exception causes the entire program to exit
2. Put all the activity into a list and then drop all the activity,finish when you need to exit
3. To complete the Exit function via broadcast
1. Manufacturing Throw exception causes the entire program to exit:
See http://blog.csdn.net/liuhe688/article/details/6584143
2. put all the activity into a list and then drop all the activity,finish when you need to exit:
Application define a collection inside
when Activity oncreate, the corresponding activity is added to the collection, when exiting, traverse the previously opened activity and close it.
for (activity activity:Lecacheapp. openactivity) {
Activity.finish ();}
android.os.Process . KillProcess (android.os.Process. Mypid ());
System.exit (0);
3. to complete the Exit function by broadcasting:
When each activity is created (OnCreate), a broadcast receiver is registered with the activity, which is sent when the broadcast exits. The approximate code is as follows:
@Override
protected void onCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
intentfilter filter = new Intentfilter ();
filter.addaction ("Finish");
registerreceiver (mfinishreceiver, filter);
}
private Broadcastreceiver mfinishreceiver = new Broadcastreceiver () {
@Override
& nbsp public void OnReceive (context context, Intent Intent) {
if ("Finish". equ ALS (Intent.getaction ())) {
LOG.E ("#########", "I am" + getlocalclassn Ame () + ", now finishing myself ...");
finish ();
}
}
};
Execute the following code on exit to close all interfaces and completely exit the program:
Getapplicationcontext (). Sendbroadcast (new Intent ("Finish"));
Common exit methods for Android apps