Getting a list of running processes and killing a specific process

此生再无相见时 提交于 2019-12-23 09:57:26

问题


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.

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.

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?


回答1:


'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.



来源:https://stackoverflow.com/questions/9839592/getting-a-list-of-running-processes-and-killing-a-specific-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!