Service restart behavior – Compilation

by Chris Koperski / from beautifuldecay.com

START_STICKY

  • Service is restarted if it gets terminated. It will tell the system to create a newest copy of the service, when available memory is sufficient to do, after it retains state and recovers from the low memory.
  • In this process we will loose the results that might have calculated before. onStartCommand() will be called on the next instance of the service with a null Intent instead of not being called at all. So, It’s used for services which manages their own state and do not depend on the Intent data.

START_NOT_STICKY

  • Service is not restarted. It will tell the system not to worry and bother about to restart the service, even when it is having sufficient available memory.
  • The service is only restarted if the runtime has pending startService() calls since the service termination.
  • This makes a lot more sense for services that are intended to only run while executing commands sent to them. For example, a service may be started every 15 minutes from an alarm to poll some network state. If it gets killed while doing that work, it would be best to just let it be stopped and get started the next time the alarm fires.

START_REDELIVER_INTENT

  • Similar to START_NOT_STICKY, except if the service’s process is killed before it calls stopSelf() for a given intent, that intent will be re-delivered to it until it completes (unless after some number of more tries it still can’t complete, at which point the system gives up).
  • This is useful for services that are receiving commands of work to do, and want to make sure they do eventually complete the work for each command sent.

Resources

Vogella, Android Reference and StackOverflow

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair /  Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )

w

Conectando a %s