private static long back_pressed;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if ((System.currentTimeMillis() - back_pressed) > 2000) {
Toast.makeText(this, "再按一次退出应用", Toast.LENGTH_SHORT).show();
back_pressed = System.currentTimeMillis();
} else {
exitApp();
}
return true;
}
}
/**
* 退出应用
*/
public void exitApp() {
finishAll();
new Thread(){
@Override
public void run() {
try {
sleep(800);
android.os.Process.killProcess(android.os.Process.myPid());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
}