开发者

Killing an app vs Killing a Service

开发者 https://www.devze.com 2023-04-03 03:36 出处:网络
I\'m using ActivityManager.killBackgroundProcesses() to kill processes by package name. Before I kill an application that doesn\'t use 开发者_JAVA百科services (such as Calculator) I can see the app li

I'm using ActivityManager.killBackgroundProcesses() to kill processes by package name. Before I kill an application that doesn't use 开发者_JAVA百科services (such as Calculator) I can see the app listed in TaskKiller and after using killBackgroundProcesses I don't see the icon. With an application that uses services I am having trouble. Even though I kill it I can still see it in TaskKiller. I am assuming it is because of the service using START_STICKY but how can I block it from getting restarted? You can use TaskKiller to kill services (it takes an additional step but it works so it is possible!). If I try to kill Pandora for example the music will stop playing but I can still see the services running when I open TaskKiller.

I'm using a loop to search through all running processes like so:

for(RunningAppProcessInfo info:activityManager.getRunningAppProcesses()){

When I find the process I am looking for I use the killBackgroundProcesses. If I kill an app with no services I can run through the loop and see that it no longer shows up in the loop. When I kill an app with services I still see the same app in the loop.

What mechanism do I need to use to block services from restarting as TaskKiller does?

Please don't answer this question with the typical "Your not supposed to do that" or "Android isn't designed to do that". My users are requesting me to automatically kill (not close) other apps. The fact that TaskKiller is doing this means it is possible.


The docs state the following about killBackgroundProcesses:

Have the system immediately kill all background processes associated with the given package. This is the same as the kernel killing those processes to reclaim memory; the system will take care of restarting these processes in the future as needed.

Note, the system will take care of restarting the service.

Therefore, if an app returns START_STICKY, there's no way to legitimately do it as of API 8. Prior to 8, you could use restartPackage, which looks like it would work.

I'm sure there is some undocumented way that it could be done, but IF you found that method, then your app could be pulled from the market as it would void the T&Cs.

Or if you make it a root application, then there might be something that would allow it, but I can't say that for sure as I have never studied what is capable with root, as far as development goes.

Note: While it's not supposed to be done, that's not what I'm trying to say. I'm just trying to say that if you want to do it, you will have to break the T&Cs or consider making it an app that requires root priveleges.

0

精彩评论

暂无评论...
验证码 换一张
取 消