public boolean onKeyDown(int keyCode, KeyEvent event) { // 两次返回退出程序 if (keyCode == KeyEvent.KEYCODE_BACK) { if ((System.currentTimeMillis() - mExitTime) > 2000) { Toast.makeText(this, R.string.toast_twice_press_back_to_exit, Toast.LENGTH_SHORT).show(); mExitTime = System.currentTimeMillis(); } else { finish(); } return true; } return super.onKeyDown(keyCode, event); }
原文地址:http://blog.csdn.net/vvcumt/article/details/39136859