Reputation: 1035
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!
Upvotes: 7
Views: 4436
Reputation: 23962
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.
Upvotes: 0
Reputation: 2685
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.
Upvotes: 1