Android中杀死所有进程
程序员文章站
2022-07-14 15:11:47
...
如果app是多进程的,而且要在退出主界面的时候杀死所有进程,可以试试如下方法:
private void killAllProcess() {
ActivityManager mActivityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> mList = mActivityManager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : mList) {
if (runningAppProcessInfo.pid != android.os.Process.myPid()) {
android.os.Process.killProcess(runningAppProcessInfo.pid);
}
}
android.os.Process.killProcess(android.os.Process.myPid());
}