Skip to content Skip to sidebar Skip to footer

Is Android Service Useful When I Don't Need Interprocess Communication?

It seems that when I don't need interprocess communication, there's almost no reason to use a Service. The only reason I am aware of is this: if my process has a started Service, t

Solution 1:

Yes, there are other reasons.

Your application runs in a process which can be killed by the system whenever it needs more resources.

According to this a running service has a higher priority than an Activity that isn't in the foreground, meaning that the system is more likely to kill an application process that has an Activity in the background than one that has a Service running in the background.

The documentation for Service states that:

If the service has been started, then its hosting process is considered to be less important than any processes that are currently visible to the user on-screen, but more important than any process not visible. Because only a few processes are generally visible to the user, this means that the service should not be killed except in extreme low memory conditions.

So, you can use Services to decrease the likelihood of your application process being killed.

Solution 2:

Even though the Service runs in the same process as an Activity nothing guarantees you that your Activity will not be killed.

From Processes and Threads:

For example, an activity that's uploading a picture to a web site should start a service to perform the upload so that the upload can continue in the background even if the user leaves the activity. Using a service guarantees that the operation will have at least "service process" priority, regardless of what happens to the activity. This is the same reason that broadcast receivers should employ services rather than simply put time-consuming operations in a thread.

Conclusion: If you want to do a background operation that will take a while and it's important it finishes correctly, use a Service.

Solution 3:

Its not necessary that if A process started service then,Process is likely to be killed.Actually process remain alive or not it does not affect service.As its completely background procedure.May be the situation that you have started a process to just start a service.So process and service can not interrelated like that.

AFAIK i did not got your final question properly.

Post a Comment for "Is Android Service Useful When I Don't Need Interprocess Communication?"