Sometimes click the fallback button to exit the application, there will be some activity can not completely quit the situation, then you can use the previous method:
In the OnCreate () method of the activity that needs to be exited, add
1 exitapplication.getinstance (). addactivity (this);
And then in the method that listens to the fallback key
BooleanStata//true to exit, false to not exit@Override Public BooleanOnKeyUp (intKeyCode, KeyEvent event) { if(KeyCode = =keyevent.keycode_back) {//I use a custom window here, if you use the default, please own Baidu. Customdialog.builder Builder=NewCustomdialog.builder ( This); Builder.settitle ("Whether to exit"); Builder.setpositivebutton ("Yes",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) { exitapplication.getinstance (). exit ();//focus on this sentence Stata=true; } }); Builder.setnegativebutton ("No",NewAndroid.content.DialogInterface.OnClickListener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Dialog.cancel (); Stata=false; } }); Builder.create (). Show (); } returnStata; }
Completely quit all acticity.