ActivityManager.killBackgroundProcesses is different from "Force stop"

I experimented with ActivityManager.killBackgroundProcesses in my application and noticed something interesting. I hope someone from stackoverflow can shed some light on this.

So, if I launch an application, for example, youtube, I first see a list of video pages, then I click menu-> Settings, I get a settings page. Now, if I press the Home button, which puts youtube in the background. So far, so good. Now, if I run ActivityManager.killBackgroundProcesses to kill the youtube application (or I use the Advanced task killer, which I believe uses the same API), and when I launch youtube again, I see the settings page, not a list of videos by by default.

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

So, it looks like ActivityManager.killBackgroundProcesses is different from stopping a forced stop, as it still remembers the last task / page it was on before it was placed in the background, while stopping an effort gives you a new start.

Does anyone have a good explanation? Is it possible to make a "forced stop" in my code to start a new application launch?

Many thanks!

+6
source share
2 answers

Well, I'm not sure how to use it exactly the way I had never tried before with applications other than mine, but maybe that would help - think about using: android.os.Process.killProcess(android.os.Process.myPid());

And about your question, why the system can stop, but you cannot. The truth is that a system can do more. More precisely, when you press the stop button, it sends a delete signal (signal 9) for processing with the given pid.

That is why I think the above function should help, because it sends almost, if not quite the same signal.

Hope this helps.

+1
source

Writing to the Android OS security system, the application cannot just kill another action. You can send a request to the system, and then he will do everything necessary for you, if possible.

Settings is a system application, so it has more access than your application.

So, it seems that the OS does not allow you to kill applications. Not sure, but try checking your permionsns application - maybe there is a solution.

0
source

Source: https://habr.com/ru/post/905552/


All Articles