From: http://blog.csdn.net/xuyide54321/article/details/7049297
Finish is the activity class. It only applies to the activity. When finish () is called, the activity is pushed to the background, and the memory is not released immediately. The activity resources are not cleared; when system. when exit (0), the entire process is killed,
At this time, the resources occupied by the activity will also be released.
When developing Android applications, you often press the return key (that is, keycode = keyevent. keycode_back) to close the program. In most cases, the application is still running in the task. In fact, this is not the result we want.
We can do this. When you click the custom exit button or return key (capture action is required), We forcibly exit the application in ondestroy () or directly kill the process.
@ Overridepublic Boolean onkeydown (INT keycode, keyevent event) {// press the return button on the keyboard if (keycode = keyevent. keycode_back) {New alertdialog. builder (this ). seticon (R. drawable. services ). settitle (R. string. prompt ). setmessage (R. string. quit_desc ). setnegativebutton (R. string. cancel, new dialoginterface. onclicklistener () {@ overridepublic void onclick (dialoginterface dialog, int which ){}}). setpositivebutton (R. string. confirm, new dialoginterface. onclicklistener () {public void onclick (dialoginterface Diener, int whichbutton) {finish ();}}). show (); Return true;} else {return Super. onkeydown (keycode, event) ;}@ overrideprotected void ondestroy () {super. ondestroy (); system. exit (0); // or the following method // android. OS. process. killprocess (Android. OS. process. mypid ());}