The Android monitor return key needs to override the OnKeyDown () method
HOME Button Keycode==keyevent.keycode_home
[Java]View PlainCopy
- @Override
- Public boolean onKeyDown (int keycode, keyevent event) {
- if (keycode = = Keyevent.keycode_back && event.getrepeatcount () = = 0) {
- //++ Custom Click events
- return true; Do not perform a click event on the parent class
- }
- return Super.onkeydown (KeyCode, event); Continue to perform other click events of the parent class
- }
Instance: Press the return key again to exit the app
[Java]View PlainCopy
- 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) > ) {
- Toast.maketext (Getapplicationcontext (), "Press exit App again", Toast.length_short). Show ();
- Exittime = System.currenttimemillis ();
- } Else {
- Finish ();
- System.exit (0);
- }
- return true;
- }
- return Super.onkeydown (KeyCode, event);
- }
Android Monitor Back button, home button + Press back again to exit the app