即使在前面运行,如何强制停止启动的进程?
我正在编写一个任务管理器服务,需要强制关闭任何正在运行的进程,比如说浏览器,我尝试使用killBackgroundProcesses,restartPackage,killProcess,但是当进程位于前面 否则他们正在工作。
我想强制停止进程,即使进程正在前端运行。 我现在该怎么办?
I am writing a task manager service and need to force close any running process, lets say browser, I tried using killBackgroundProcesses,restartPackage,killProcess but none of these force closes process ( e.g browser ) when process is on front else they are working.
I want to force stop the process even when process is running on front.
What should I do now ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
已解决,代码如下:
Solved, here is the code:
我和你一样遇到了这个问题。我在服务中使用了一种方法来杀死后台进程。所以每当我需要杀死在前台运行的进程时,我只是将我的 Activity 带到前台。所以想要杀死的进程会自动消失背景,可以用killBackgroundProcess 杀死。
但这肯定不是一个好的做法
I had this problem like you.I used a method in the service that killed the background process.So whenever i need to kill process that is running in the foreground i just brought my Activity in the foreground.So the process want to kill automatically goes background and can be killed with killBackgroundProcess.
But surely this is not really a good practice