How to prevent a service from stopping when onTaskRemoved is calls?

I have a problem with Service music, which stops after “Scrolling to Exit” is executed in the last list of applications in ICS. The service was started using START_REDELIVER_INTENT , and it automatically restarts after a few seconds, but I want to prevent the stop altogether.

“Swipe to go out” is generally unknown, and I base all my knowledge on this topic. It contains comments from one of the Google employees:

[W] hat especially happens when you delete a recent task: (1) it kills any background or empty application processes (see http://developer.android.com/guide/topics/fundamentals/processes-and-threads.html# Lifecycle for what this means), and (2) uses the new API http://developer.android.com/reference/android/app/Service.html#onTaskRemoved(android.content.Intent) to talk about any application services about deleting a task so that he can do everything that, in his opinion, is appropriate.

and

In fact, deleting a record in recent tasks will destroy any background processes that exist for the process. It will not directly cause the services to stop, however there is an API for them to find out if the task has been deleted, to decide if they want it to mean that they should stop. This means that the deletion indicates that the recent task of the email application will not cause it to stop checking email. If you really want to completely stop the application, you can click on recent tasks for a long time to go to the information about the application and hit it. To stop - this is the complete destruction of the application - all processes are killed, all services are stopped, all notifications are deleted, all alarms are deleted, etc. The application is not allowed to run again until explicitly requested.

According to the second comment, my Service must decide what he wants to do - instead, it stops without any action with me and restarts later.

Any ideas what to do with it? Using START_STICKY works exactly the same ...

+4
source share
1 answer

Put your service on foreground . Please note that you will need to display the current notification while the service is running in the foreground.

0
source

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


All Articles