It is necessary for the user to give a prompt before exiting the application, because it may be because the user does not really want to exit, but accidentally presses the return key, most applications provide a dialog before exiting the application. I don't think this is very friendly. You have to move your finger to press the button in the dialog. I personally think that "click back again to exitProgram"Is best practice, the implementation is also very simple, directly onCode:
Private long exittime = 0;
@ Override
Public Boolean onkeydown (INT keycode, keyevent event ){
If (keycode = keyevent. keycode_back & event. getaction () = keyevent. action_down ){
If (system. currenttimemillis ()-exittime)> 2000 ){
Toast. maketext (getapplicationcontext (), "exit the program once again", Toast. length_short). Show ();
Exittime = system. currenttimemillis ();
} Else {
Finish ();
System. Exit (0 );
}
Return true;
}
Return super. onkeydown (keycode, event );
}