/**
* 退出程序提醒
*/
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if (!FINISH) {
Toast backToast = Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT);
backToast.show();
FINISH = true;
new Timer().schedule(new TimerTask() {
@Override
public void run() {
FINISH = false;
}
}, 2000);
} else {
return super.dispatchKeyEvent(event);
}
return true;
}
return super.dispatchKeyEvent(event);
}
说明:根据自己的需要,修改Toast的内容。