获取运行中的进程列表,并杀死一个特定的进程 [英] Getting a list of running processes and killing a specific process

查看:115
本文介绍了获取运行中的进程列表,并杀死一个特定的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我执行下面的一段code的:

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());

其中,过程是一款入门 procInfos

问题是如果我跑 getRunningTasks 再次 - 它仍然会显示我(presumably)被杀的过程,而对于Android的任务管理器列出的过程之前,调用 killBackgroundProcesses 和调用后从列表中删除它。

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?

推荐答案

运行,并不意味着用户启动它;它可能会被监听的事件,做了预定的后台同步或其他任何东西。

'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()可能会接近你想要什么,但在本质上,你总是会存在这个问题,因为用户没有对什么是当前活动的完全控制。

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.

这篇关于获取运行中的进程列表,并杀死一个特定的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆