Android press the return key to exit the program. There is nothing to say. paste the Code directly:
Public Boolean onkeydown (INT keycode, keyevent event) {If (keycode = keyevent. keycode_back & event. getrepeatcount () = 0) {// confirmation dialog box final alertdialog isexit = new alertdialog. builder (this ). create (); // the title of the dialog box isexit. settitle ("system prompt"); // The message isexit in the dialog box. setmessage ("are you sure you want to exit? "); // Click the button in the instantiation dialog box to listen to the dialoginterface. onclicklistener listener = new dialoginterface. onclicklistener () {public void onclick (dialoginterface Diener, int which) {Switch (which) {Case alertdialog. button1: // "OK" button to exit the program icationicationmanager notificationmanager = (notificationmanager) mainactivity. this. getsystemservice (icationication_service); icationicationmanager. cancel (0); string packagename = getpackagename (); activitymanager manager = (activitymanager) getsystemservice (activity_service); finish (); If (getsystemversion () <8) {manager. restartpackage (getpackagename ();} else {manager. killbackgroundprocesses (packagename);} break; Case alertdises. button2: // "cancel" second button cancel dialog box isexit. cancel (); break; default: Break ;}}; // register the listener isexit. setbutton ("OK", listener); isexit. setbutton2 ("cancel", listener); // display the isexit dialog box. show (); Return false;} return false ;}