I didn't refer to other people's methods on the Internet before, and my ideas were always dull. The method used previously is to set an int sign, 0 and 1. Determine if it is 0, no, add 1, yes, and exit. This low-level error is really embarrassing. As a result, it will exit after several long intervals. Later I came up with a timer to set the time. Low efficiency. In fact, java has an API that can directly obtain the current time, and the time minus the previous time will not be able to get the interval?
Code:
Private long mExitTime; // Exit Time
// Capture the key @ Overridepublic boolean onKeyDown (int keyCode, KeyEvent event) {if (keyCode = KeyEvent. KEYCODE_BACK & event. getRepeatCount () = 0) {if (System. currentTimeMillis ()-mExitTime)> 2000) {Toast. makeText (this, "once again withdraw the vertical and horizontal material price", Toast. LENGTH_SHORT ). show (); mExitTime = System. currentTimeMillis ();} else {SysApplication. getInstance (). exit ();} return true;} return super. onKeyDown (keyCode, event );}
Here SysAppication. getInstance (). exit (); is a class encapsulated by myself. Replace your own.