By pressing the back key two times, the Toast prompt pops up and the Exit function is pressed again. The key code is as follows:
The first way:
/** * Press two times to return the key to exit */private int keybackclickcount = 0; @Override protected void Onresume () {super.onresume (); Keybackclickcount = 0; } @Override public boolean onKeyDown (int keycode, keyevent event) {//TODO auto-generated method stub if (keycode = = keyevent.keycode_back) {switch (keybackclickcount++) {case 0: Toast.maketext (this, getresources (). getString (R.string.press_again_exit), Toast.length_short). Show (); Timer timer = new timer (); Timer.schedule (New TimerTask () {@Override public void run () { Keybackclickcount = 0; }}, 3000); Break Case 1:mframetv.setvisibility (view.visible); Mimgtv.setvisibility (View.visible); Animation anim = animationutils.loadanimation (Mainactivity.this, R.anim.tv_off); Anim.setanimationlistener (New Tvoffanimlistener ()); Mimgtv.startanimation (ANIM); Break Default:break; } <span style= "color: #ff0000;" > Return true;</span>} else if (keycode = = Keyevent.keycode_menu) {if (sm.ismenushowing ()) { Toggle (); } else {showmenu (); }} return Super.onkeydown (KeyCode, event); }
The second way:
/** * Exit */private Boolean iswaitingexit = False by pressing the return key two times consecutively, @Overridepublic boolean onKeyDown (int keycode, keyevent event) { TODO auto-generated method stubif (keycode = = Keyevent.keycode_back) {if (iswaitingexit) {iswaitingexit = False;mframet V.setvisibility (0); mimgtv.setvisibility (0); Animation anim = animationutils.loadanimation (Mainactivity.this, R.anim.tv_off); Anim.setanimationlistener (new Tvoffanimlistener ()); Mimgtv.startanimation (anim);} else {Toast.maketext (This,getresources (). getString (R.string.press_again_exit), Toast.length_short). Show (); Iswaitingexit = true; Timer timer = new timer (); Timer.schedule (new TimerTask () {@Overridepublic void run () {iswaitingexit = false;}}, +); Retu RN true;} return true;} else if (keycode = = Keyevent.keycode_menu) {if (sm.ismenushowing ()) {toggle ();} else {showmenu ();}} Return Super.onkeydown (KeyCode, event);}
Android implementation Press two times back key to exit the app interface