Android 首页双击返回桌面

    //记录用户首次点击返回键的时间
    private long firstTime = 0;

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                long secondTime = System.currentTimeMillis();
                if (secondTime - firstTime > 2000) {
                    ToastUitl.showShort("再按一次退出程序");
                    firstTime = secondTime;
                    return true;
                } else {
                    BaseApplication.finishActivity();
                    System.exit(0);
                }
                break;
            default:
                break;
        }
        return super.onKeyUp(keyCode, event);
    }

 

你可能感兴趣的:(Android)