点击连着两次回车键退出程序

实现这种功能的思路是:当第一次点击回车键时,将isExit置为true,若在两秒以内再次点击退出程序,否的话则isExit置为false。

private boolean isExit = false;

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:              
                    exit();
                break;
        }
        return false;
    }

连着两次点击退出登录


    private void exit() {
        if (!isExit) {
            isExit = true;
            Tools.toastTools(this, "再次点击退出程序!");
            mHandler.sendEmptyMessageDelayed(0, 2000);
        } else {
            ActivityManager.AppExit();
        }
    }
 private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            isExit = false;
        }
    };

你可能感兴趣的:(Android基础)