Android 双击返回键退出应用程序

long mExitTime = 0L;

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (KeyEvent.KEYCODE_BACK == keyCode) {
        if (System.currentTimeMillis() - mExitTime > 2000) {
            toast("再按一次退出程序");
            // 将系统当前的时间赋值给exitTime
            mExitTime = System.currentTimeMillis();
        } else {
            finish();
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

标签: none

添加新评论