private long firstTime = 0;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
long secondTime = System.currentTimeMillis();
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (secondTime - firstTime < 2000) {
System.exit(0);
} else {
Toast.makeText(getApplicationContext(), "再按一次返回键退出", Toast.LENGTH_SHORT).show();
firstTime = System.currentTimeMillis();
}
return true;
}
return super.onKeyDown(keyCode, event);
}
点击两次系统返回键退出(两秒)
最新推荐文章于 2022-11-07 18:24:11 发布