ActivityManager.killBackgroundProcesses different from "Force stop"
Asked Answered
C

2

7

I was experimenting with ActivityManager.killBackgroundProcesses in my application and notice something interesting. I hope someone on stackoverflow can shed some light on this.

So if I start an application, for example, youtube, I first see the list of video page, then I click menu->Settings, I will get the settings page. now if I click home button, which will put youtube to background. so far so good. Now if I run ActivityManager.killBackgroundProcesses to kill youtube application (or I use Advanced task killer which I believe using the same API), and when I launch youtube again, I see the setting page, not the default list of video page.

But if instead of doing ActivityManager.killBackgroundProcesses, I go to system settings->manage application->Youtube->Force stop, and when I launch youtube again, I get the list of video page, not the setting page.

So it seems that ActivityManager.killBackgroundProcesses is different from force stop as it still remembers the last task/page it was on before it was put to background, whereas force stop gives you a fresh start.

Anyone has good explanation for it? Is it possible in my code to do "force stop" to get a fresh start of the application?

Many thanks!

Cordwainer answered 9/1, 2012 at 19:19 Comment(2)
Just to clarify, the app I am trying to kill/restart are third party apps, such as gmail, youtube, etc. which i can't change their code.Cordwainer
Found from an old post on Google. groups.google.com/group/android-developers/browse_thread/thread/… So it seems that "Force stop" was implemented with restartPackage, but in 2.2, restartpackage was basically removed and it becomes basically the same as killbackgroundprocess. I am guessing that 2.2 and later must be using a new API to kill the process, but it is not documented...Cordwainer
J
1

Well, I am not sure how use it exactly as I have never try before with apps other than mine, but mayby it would help - think about using: android.os.Process.killProcess(android.os.Process.myPid());

And about your question why system can stop and you can't. The truth is that system can more. More specyfic, when you press force stop button system is sending kill signal (signal 9) to process with given pid.

This is why I think the above function should help, because it is sending almost, if not exactly this same, signal.

Hope it will help.

Jehoshaphat answered 9/1, 2012 at 20:18 Comment(1)
Thanks for the suggestion. But it does not help my case. killProcess will not kill applications that I don't own, for example, gmail, youtube, etc. I tried it and it has no effect on those apps.Cordwainer
I
0

Recording to Android OS security system your app can't just kill another activity. You can send request to system and then it will do all required stuff for you, if it possible.

Settings is system application, that's why it has more access than your app.

So, looks like OS not allowed you to kill apps. Not sure, but try to check your app permisionns - maybe solution is there.

Inferior answered 9/1, 2012 at 20:30 Comment(2)
Yes and no. killBackgroundProcesses does allow you to close the process, but it seems that it is not a "hard" close as force close. It still retains some state from previous run like remembering where it was left off last time.Cordwainer
Is application stays in "settings->manage application" after .killBackgroundProcesses ?Inferior

© 2022 - 2024 — McMap. All rights reserved.