from:http://blog.csdn.net/ldj299/article/details/7574365
Personally feel that when the user presses the Back button, the prompt "Press again to exit" prevents the error from being manipulated more humanely than a dialog box is displayed. Words not much to say on the code:
The first type: rewrite onkeydown to listen:
LongWaitTime = 2000; LongTouchtime = 0; @Override Public BooleanOnKeyDown (intKeyCode, KeyEvent event) { if(event.getaction () = = Keyevent.action_down && Keyevent.keycode_back = =keycode) { LongCurrentTime =System.currenttimemillis (); if((Currenttime-touchtime) >=waitTime) {Toast.maketext ( This, "Press again to exit", Toast.length_short). Show (); Touchtime=currenttime; }Else{finish (); } return true; } return Super. OnKeyDown (KeyCode, event); }
The second is to override the Onbackpressed method to directly listen for the return key:
@Override Public void onbackpressed () {// super.onbackpressed (); long currenttime = system.currenttimemillis (); if ((currenttime-touchtime) >= waitTime) { Toast.maketext (this, "Press Exit Again", Toast.length_short). Show (); = currenttime; } Else { finish (); } }
"Go" Android implementation "press again to exit the program"