2次退出
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (isExit == false) {
isExit = true; // 准备退出
Toast.makeText(this, "再按一次退出程序", 0).show();
Timer tExit = new Timer();
tExit.schedule(new TimerTask() {
@Override
public void run() {
isExit = false; // 取消退出
}
}, 2000); // 如果2秒钟内没有按下返回键,则启动定时器取消掉刚才执行的任务
} else {
return super.onKeyDown(keyCode, event);
}
}
return false;
}
private static Boolean isExit = false;