The Android monitor return key needs to override the OnKeyDown () method
HOME Button Keycode==keyevent.keycode_home
@Override Public boolean onKeyDown (int keycode, keyevent event) { if (keycode = = Keyevent.keycode_back & & Event.getrepeatcount () = = 0) { //do someting return true; } Return Super.onkeydown (KeyCode, event); }
Instance: Press the return key again to exit the app
Private long exittime = 0; @Overridepublic boolean onKeyDown (int keycode, keyevent event) { if (keycode = = KEYEVENT.KEYC Ode_back && event.getaction () = = Keyevent.action_down) { if (System.currenttimemillis ()-exittime) > () { toast.maketext (Getapplicationcontext (), "Press Exit application Again", Toast.length_short). Show (); Exittime = System.currenttimemillis (); } else { finish (); System.exit (0); } return true; } Return Super.onkeydown (KeyCode, event);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Monitor Back button, home button + Press back again to exit the app