简体   繁体   English

获取正在运行的进程列表并杀死特定进程

[英]Getting a list of running processes and killing a specific process

I'm executing the following piece of code: 我正在执行以下代码:

ActivityManager actvityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<RunningTaskInfo> procInfos = actvityManager.getRunningTasks(1000);

Then, I kill one process I'm interested in with 然后,我杀死了一个我感兴趣的进程

actvityManager.killBackgroundProcesses(process.baseActivity.getPackageName());

where process is an entry from procInfos . 其中processprocInfos的条目。

The problem is if I run getRunningTasks again - it would still show the process I (presumably) killed, while a task manager for Android listed that process before calling killBackgroundProcesses and removed it from list after that call. 问题是如果我再次运行getRunningTasks它仍然会显示我(大概)已杀死的进程,而Android的任务管理器在调用killBackgroundProcesses之前列出了该进程,并在该调用之后将其从列表中删除。

So, any ideas on how does task manager get its list of running processes? 那么,关于任务管理器如何获取其正在运行的进程列表的任何想法? And is it normal that I have successfully killed 3rd-party process on an unrooted device? 在无根设备上成功杀死第三方进程是否正常?

'Running' doesn't mean that a user started it; “运行”并不意味着用户已启动它。 it might be listening for events, doing a scheduled background sync or anything else. 它可能正在侦听事件,进行预定的后台同步或其他任何操作。

ActivityManager.getRunningTasks() might be closer to what you want, but in essence you are always going to have this problem, because the user is not in full control over what is currently active. ActivityManager.getRunningTasks()可能更接近您想要的内容,但从本质上讲,您始终会遇到此问题,因为用户无法完全控制当前活动的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM