退出整个应用解决方案
1、配合FLAG_ACTIVITY_CLEAR_TOP使用,但是service不能被杀掉
private void showTips() { AlertDialog alertDialog = new AlertDialog.Builder(this).setTitle("提醒").setMessage("是否退出程序") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //startActivity先清楚之前所有的activity再跳转到主界面 Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); //杀死当前进程,只能消灭当前Activity android.os.Process.killProcess(android.os.Process.myPid()); } }).setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }) .create(); // 创建对话框 alertDialog.show(); // 显示对话框 }
Done