- 定义一个long类型的时间戳 判断当前时间 减去long类型时间戳的时间 是否超过两秒
- long nowTime;
-
-
public boolean onKeyDown(int keyCode, KeyEvent event) {
-
if (keyCode == KeyEvent.KEYCODE_BACK) {
-
if ((System.currentTimeMillis() -
nowTime) > 2000) {
-
Object mHelperUtils;
-
Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
-
mExitTime = System.currentTimeMillis();
-
-
} else {
-
finish();
-
}
-
return true;
-
}
-
return super.onKeyDown(keyCode, event);
-
}
- }
双击返回,退出应用。
最新推荐文章于 2019-01-22 10:13:07 发布