Http://www.2cto.com/kf/201402/276808.html
Android program when clicking the fallback button, if there is only one activity, call the finish () method can exit the interface, if there are multiple interfaces, when invoking the method, will only destroy the current activity, showing the top of the stack other activity, in other words, Is that you cannot exit the entire application. The following is a quick way to exit the entire application code:
private void Showtips () {Alertdialog alertdialog = new Alertdialog.builder (this). Settitle ("Reminder"). s Etmessage ("Whether to quit the program"). Setpositivebutton ("OK", new Dialoginterface.onclicklistener () {PU Blic void OnClick (dialoginterface dialog, int which) {Intent Intent = new Intent (intent.action_mai N); Intent.addcategory (Intent.category_home); Intent.setflags (Intent.flag_activity_clear_top); StartActivity (Intent); Android.os.Process.killProcess (Android.os.Process.myPid ()); }}). Setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {PU Blic void OnClick (dialoginterface dialog, int which) {return; }}). Create (); Create dialog box Alertdialog.show (); Show dialog box
@Override Public boolean onKeyDown (int keycode, keyevent event) { //TODO auto-generated method Stub if (KEYC Ode = = Keyevent.keycode_back && event.getrepeatcount () = = 0) { showtips (); return false; } Return Super.onkeydown (KeyCode, event); }
Android Perfect Exit app.