获取正在运行的进程列表并终止其后台服务 [英] Get Running Processes List and Kill Their Background Services
本文介绍了获取正在运行的进程列表并终止其后台服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个用于 RAM 优化的 Android 应用.我可以使用此 answer 成功获取正在运行的进程列表(及其 PID).但是,我没有看到通过 PID 杀死他们或他们的后台服务的方法.
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.
推荐答案
事实证明这是非常基本的事情:
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);
}
这篇关于获取正在运行的进程列表并终止其后台服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文