当前位置: 代码迷 >> Android >> android 再按一次退后键退出应用程序
  详细解决方案

android 再按一次退后键退出应用程序

热度:97   发布时间:2016-05-01 20:48:33.0
android 再按一次后退键退出应用程序
private static Boolean isExit = false;    private static Boolean hasTask = false;    Timer tExit = new Timer();    TimerTask task = new TimerTask() {                 @Override        public void run() {            isExit = false;            hasTask = true;        }    };         @Override    public boolean onKeyDown(int keyCode, KeyEvent event) {        System.out.println("TabHost_Index.java onKeyDown");        if (keyCode == KeyEvent.KEYCODE_BACK) {            if(isExit == false ) {                isExit = true;                Toast.makeText(this, "再按一次后退键退出应用程序", Toast.LENGTH_SHORT).show();                if(!hasTask) {                    tExit.schedule(task, 2000);                }            } else {                finish();                System.exit(0);            }        }        return false;    }
  相关解决方案