Java:
Public classMainactivity extends Activity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); } //When you click the Physical button, the exit prompt is executed PublicBoolean OnKeyDown (intKeycode,keyeventEvent){ if(Keycode==keyevent.keycode_back &&Event. Getrepeatcount () = =0) {creatdialog (); } return false; } Private voidCreatdialog () {//TODO auto-generated Method StubAlertdialog.builder b=NewBuilder (mainactivity. This); //set the content of the prompt boxB.setmessage ("you sure you quit?"); //set the title barB.settitle ("Tips"); B.setpositivebutton ("Confirm",NewOnclicklistener () { Public voidOnClick (Dialoginterface Dialog,intwhich) { //TODO auto-generated Method Stub//exit the program when the point is OK and hide this dialog boxDialog.dismiss (); Mainactivity. This. Finish (); }}). Setnegativebutton ("Cancel",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) { //TODO auto-generated Method Stub//just hide the dialog box when you click CancelDialog.dismiss (); } }); B.create (). Show (); } }
Android Base top4_1: Click the physical button to eject the exit prompt box