@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (isExit == false) { isExit = true; Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show(); if (!hasTask) { tExit.schedule(taskExitCheck, 2000); } } else { finish(); } return false; } return super.onKeyDown(keyCode, event); } private Boolean isExit = false; private Boolean hasTask = false; Timer tExit = new Timer(); TimerTask taskExitCheck = new TimerTask() { @Override public void run() { isExit = false; hasTask = true; } };