连续点击返回键,退出应用程序
今天试了一下,比较常用的退出app方式,快速连击返回键,退出应用程序,不多说,上代码:
// 退出时间private long currentBackPressedTime = 0;// 退出间隔private static final int BACK_PRESSED_INTERVAL = 2000;//在activity中重写onBackPressed方法@Overridepublic void onBackPressed() {// 判断时间间隔if (System.currentTimeMillis() - currentBackPressedTime > BACK_PRESSED_INTERVAL) {currentBackPressedTime = System.currentTimeMillis();Toast.makeText(this, "再按一次返回键退出程序", Toast.LENGTH_SHORT).show();} else {// 退出SysApplication.Quit(this);}}
另一种方法是:重写onKeyDown方法,里面写一个popupwindow展示
@Overridepublic boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent) {switch (paramInt) {case 4:PopupUtil.showOutPop(this, this.homePageMainLayout);default:return false;}}