Get Running Processes List and Kill Their Backgrou

2019-02-05 07:14发布

I am building an Android app for RAM optimization. I can successfully get the list of running processes (and their PIDs) using this answer. However, I don't see a way to kill them or their background services by PID.

1条回答
欢心
2楼-- · 2019-02-05 07:48

It turned out to be something very basic:

ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

for (RunningAppProcessInfo pid : am.getRunningAppProcesses()) {
    am.killBackgroundProcesses(pid.processName);
}
查看更多
登录 后发表回答