标签:android http color java os io 2014 ar
Android 程序在点击回退键时,如果只有一个activity,调用finish()方法就能退出界面,如果有多个界面,在调用该方法时,只会销毁当前的activity,显示栈顶的其它activity,换言之,就是无法退出整个应用程序。下面是一种快速的退出整个应用的方法代码:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | privatevoidshowTips() {          AlertDialog alertDialog = newAlertDialog.Builder(this).setTitle("提醒")                 .setMessage("是否退出程序")                 .setPositiveButton("确定", newDialogInterface.OnClickListener() {                      publicvoidonClick(DialogInterface dialog, intwhich) {                         Intent intent = newIntent(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());                     }                  }).setNegativeButton("取消",                  newDialogInterface.OnClickListener() {                     publicvoidonClick(DialogInterface dialog, intwhich) {                         return;                     }                 }).create(); // 创建对话框         alertDialog.show(); // 显示对话框     } | 
| 1 2 3 4 5 6 7 8 9 10 | @Override    publicbooleanonKeyDown(intkeyCode, KeyEvent event) {         // TODO Auto-generated method stub         if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {             showTips();             returnfalse;         }          returnsuper.onKeyDown(keyCode, event);     } | 
android 完美退出应用程序。,布布扣,bubuko.com
标签:android http color java os io 2014 ar
原文地址:http://www.cnblogs.com/manmanlu/p/3905267.html