private long exitTime = 0; @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Log.d("keyCode:",String.format("%1$d", keyCode)); // 可藉此攔截來避免程式被離開 if (keyCode == 4) {// back key ExitApp(); return false; } else {// other key return true; } } public void ExitApp() { if ((System.currentTimeMillis() - exitTime) > 2000) { Toast.makeText(this, "再按一次退出程式", Toast.LENGTH_SHORT).show(); exitTime = System.currentTimeMillis(); } else { finish(); } }
按 Back 兩次才關閉程式
週四, 2013-02-07 10:00
#1
按 Back 兩次才關閉程式