The remote service is killed while the main process is associated with it

On my Galaxy Nexus with Bean 4.1.1 jelly (official), sometimes the OS goes into a hurricane boom, and the journal has the following entries:

10-02 22:24:34.992 I/ActivityManager( 306): Killing 7517:com.google.android.apps.reader/u0a77: remove task 10-02 22:24:36.484 I/ActivityManager( 306): Killing 7465:com.tf.thinkdroid.sg:writedroid/u0a50: remove task 10-02 22:24:37.273 I/ActivityManager( 306): Killing 5924:com.metago.astro/u0a73: remove task 10-02 22:24:37.296 W/ActivityManager( 306): Scheduling restart of crashed service com.metago.astro/.jobs.JobService in 5000ms 10-02 22:24:37.656 I/ActivityManager( 306): Killing 7302:org.jtb.alogcat/u0a84: remove task 10-02 22:24:38.148 I/ActivityManager( 306): Killing 7120:com.google.android.gm/u0a19: remove task 

Unfortunately, one of the processes to be killed is my remote service, to which a working application is bound. Indeed, the service starts immediately after that, but this causes inconsistent behavior in my application.

In the service life cycle , it says:

A service can be started and associated with it. In this case, the system will support the service until either it is running, or there is one or more connections to it using the Context.BIND_AUTO_CREATE flag.

My application is bound to a remote service using Context.BIND_AUTO_CREATE , so it seemed to me that the remote service would not work while the main process was attached to it. How can I get Android to not kill a remote service?

NOTE. The bounty explains why the code does not seem to work as per the documentation.

+6
source share
3 answers

Please read this answer from Joel F here: How is this possible? The service runs indefinitely and also allows binding in android?

As already mentioned, if there really is a need for resources, the only way to save your service is unkillable - use foreground service http://developer.android.com/guide/components/services.html#Foreground

The documentation is also spelled incorrectly because the citation system: โ€œwill keep the service running while it is running or has one or more connections to itโ€, this is not true in 100% of cases. The Context.BIND_AUTO_CREATE flag will give you a higher privilege, but not high enough to keep it unkilable. Other services will be killed first, and if there is still a need for ressourcees, your privileged service will also be killed.

+4
source

A service is a component of an application that runs in a process. Although, according to the service life-cycle documentation, the process containing the service should not have been killed, but there are other cases where Android can kill.

In case of resource shortage, the priority will be performed with priority, and the process with lower priority. Now, if there are several processes in which there are services that are promised not to kill according to the life cycle of the service, Android will prioritize and kill the process with a lower priority.

Android may decide to shut down the process at some point when the memory is low and is required by other processes that are more serving the user. Application components running in a process that is killed, therefore destroyed. The process starts again for these components when they work again for them.

When you decide which processes to kill, the Android system weighs their relative importance to the user. For example, it more easily closes actions for hosting a process that are no longer visible on the screen, compared to a process in which there are visible actions. The decision, therefore, to terminate the process, therefore, depends on the state of the components running in the process.

Quote from here: http://developer.android.com/guide/components/processes-and-threads.html

When the operating system is operating in an irregular mode, it is forced to make decisions, violating fair promises :)

+4
source

To set up un-killable services, please look at the persistent Android services: http://devescape.blogspot.ch/2011/02/persistent-services-in-android.html

+1
source

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


All Articles