android退出

private void exitBy2Click() {
        Timer tExit = null;
        if (isExit == false) {
            isExit = true; // 准备退出
            ToastUtils.showToast(context, "再按一次退出");
            tExit = new Timer();
            tExit.schedule(new TimerTask() {
                @Override
                public void run() {
                    isExit = false; // 取消退出
                }
            }, 2000); // 如果2秒钟内没有按下返回键,则启动定时器取消掉刚才执行的任务

        } else {
            ToastUtils.dismissToast();
            if (LoginActivity.context != null)
                LoginActivity.context.finish();
            finish();
        }
    }

posted @ 2015-11-10 11:52  蜗牛眼里的世界  阅读(113)  评论(0编辑  收藏  举报