// ExitProgramPrivate Static Boolean isexit = false; // time trigger Private Static timer texit = NULL;
Public Boolean onkeyup (INT keycode, keyevent event) {If (keycode = keyevent. keycode_back) {If (isexit = false) {isexit = true; If (texit! = NULL) {texit. cancel (); // remove the original task from the queue} // re-instance a timer texit = new timer (); timertask task = new timertask () {@ overridepublic void run () {isexit = false ;}}; toast. maketext (this, "exit the program again", toast. length_short ). show (); // triggers the task texit in two seconds. schedule (task, 2000);} else {finish (); system. exit (0);} return true;} return Super. onkeyup (keycode, event );}
The principle is simple: Define a timertask timer and an exit program id isexit. Press the return key for the first time, assign the value isexit to true, enable the timertask timer, and assign the value isexit to false after two seconds, therefore, if you press the return key again within these two seconds, the program will exit. Otherwise, the timer timertask task is executed, which indicates false. The principle is so simple ~