Intent intent = new Intent(Intent.ACTION_MAIN);intent.addCategory(Intent.CATEGORY_HOME);intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);startActivity(intent);android.os.Process.killProcess(android.os.Process.myPid());

先退出到桌面,然后杀死所有进程。这样就不用烦恼,很多activity反复跳出了。

下面给出一个常用的按两次退出程序的写法

private long exitTime;    //两次返回键退出之间的间隔
//按两次退出程序@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK&& event.getAction() == KeyEvent.ACTION_DOWN) {if ((System.currentTimeMillis() - exitTime) > 2000) // System.currentTimeMillis()无论何时调用,肯定大于2000{Toast.makeText(getApplicationContext(), "亲爱滴,再按一次退出程序",Toast.LENGTH_SHORT).show();exitTime = System.currentTimeMillis();} else {Intent intent = new Intent(Intent.ACTION_MAIN);intent.addCategory(Intent.CATEGORY_HOME);intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);startActivity(intent);android.os.Process.killProcess(android.os.Process.myPid());}return true;}return super.onKeyDown(keyCode, event);}

更多相关文章

  1. Android完全退出应用程序
  2. android 2.2+ 完全退出程序的方法今天贡献了
  3. Android(安卓)返回键退出APP
  4. android 退出程序
  5. android使用finish()和System.exit()退出应用程序的理解
  6. android再点一次返回退出
  7. Android(安卓)动态设置全屏,退出全屏
  8. Android(安卓)点击back键两次退出程序
  9. android 老是弹出 "Copy" did not complete normally. Please se

随机推荐

  1. Android之drawable state各个属性详解
  2. Android(安卓)应用程序基础知识(2)
  3. Android(安卓)Lint & Checkstyle
  4. Android图片太大导致无法正常显示
  5. listView加快scroll
  6. 【Android】Android(安卓)apk默认安装位
  7. android的图片添加、滚动条、单选框、多
  8. 【Android(安卓)界面效果39】android:inp
  9. android:shape的使用
  10. Android之drawable state各个属性详解