private long exitTime = 0;
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
if ((System.currentTimeMillis() - exitTime) > 2000) {
Toast.makeText(getApplicationContext(), "再按一次退出应用", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
} else {
ExitActivity.exit();
}
return true;
}
return super.onKeyDown(keyCode, event);
}
重写返回键==>1秒内按两次返回键才能退出
最新推荐文章于 2019-10-23 15:35:28 发布