/** * 设置高速双击退出程序 */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_BACK) { exitBy2Click(); } return false; } /** * 双击退出函数 zhaoyazhi */ private void exitBy2Click() { // TODO Auto-generated method stub Timer tExit = null; if (isExit == false) { isExit = true;// 准备退出 Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show(); tExit = new Timer(); tExit.schedule(new TimerTask() { @Override public void run() { isExit = false;// 取消退出 } }, 2000);// 假设2秒没有按下返回键则启动定时器取消掉刚才运行的任务 } else { // 结束全部的界面和后台程序 AccessTokenKeeper.clear(getApplication()); ActivityManager activityMgr = (ActivityManager) getSystemService(ACTIVITY_SERVICE); activityMgr.restartPackage(getPackageName()); MyApp.getInstance().exit(); System.exit(0); finish(); } }