//退出时的时间
private long mExitTime;
//对返回键进行监听
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
exit();
return true;
}
return super.onKeyDown(keyCode, event);
}
public void exit() {
if ((System.currentTimeMillis() - mExitTime) > 2000) {
Toast.makeText(MainActivity.this, "再按一次退出当前应用程序", Toast.LENGTH_SHORT).show();
mExitTime = System.currentTimeMillis();
} else {
finish();
System.exit(0);
}
}
Android两次返回键退出APP(总结)
最新推荐文章于 2024-10-14 11:27:14 发布