When should I use Android Service?

by Andres Amador / from beautifuldecay.com

To rank higher the process which is hosting my application

Because a process running a service is ranked higher than a process with background activities, an activity that initiates a long-running operation might do well to start a service for that operation, rather than simply create a worker thread.

An activity can be stopped or destroyed, the process which hosts it will lose priority even if your application is doing something important in background. Lose priority means increase the probability to be eliminate by the OS when it needs memory space and it would be terrible because something important is happening there….

If you want to avoid the lose of priority and ensure that your task will be executed until the end even if you process doesn’t have a foreground activity, you should put your task in a service.

A process which hosts a service is ranked only below process which hosts the Activity which is visible for the user (Foreground), so, it has higher priority than process which has only stopped activities.

Imagine, your important task is inside a service. If the process which hosts this service has an activity in foreground, the chance to be eliminate by the OS is almost 0%. If this activity is moved to background, this process will lose just a bit of priority, increasing only slightly likely to be eliminated, because this process has a service being executed. The otherwise, without the service and foreground activity, it is lost much priority, the chance to be eliminated would be enormous and your task could be interruped.

To Execute Important Tasks and Esure a Good User Experience

So, if the service can keep your process safe or be eliminated, it can keep a good user experience of important tasks. So, use services for execute tasks which are important for the user experience.

Although service processes are not directly tied to anything the user sees, they are generally doing things that the user cares about (such as playing music in the background or downloading data on the network), so the system keeps them running unless there’s not enough memory to retain them along with all foreground and visible processes.

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 )

Imagem do Twitter

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

Foto do Facebook

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

Foto do Google+

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

Conectando a %s