On Wed, Jun 15, 2011 at 10:04 AM, appel <[email protected]> wrote:

> I'm trying to understand the lifecycle of services. What I don't quite get
> is when should I ensure my service is stopped when done with its work and
> when should I just leave it running in case it is needed again.
>

Generally speaking, if the service is done with it's work, it should be
stopped. You can leave the caching and re-using of the service to the
system.


>  Is there a cost to starting a service?
>

Of course - there is a cost to running any code - though I doubt it's so
expensive as to warrant trying to keep the service alive.


> If I know that my service will do things once per hour for example, is it
> best to stop it in between or should I leave it running?
>

I would stop it. The system can and will kill your service when it needs to
anyway so attempting to keep it alive is mostly futile.


> Looking at other apps it would seem starting a service is expensive and
> that I should basically always leave it running. From the looks of it that
> is what Google Maps, Google Music, Email, Spotify, DoggCatcher, Google
> Listen and more does at least.
>

Don't go off of what other apps do - specially Google apps, which very
frequently don't "play by the rules". Google Maps for example apparently
likes to keep an ever-lasting service that somehow cannot be killed via the
app management screen. Why this app starts a service even when I haven't
launched the app and then cannot be killed is perplexing and annoying.

You do not want your app showing up on the user's "running services" list
when you're doing nothing. To the average user it will appear as if you're
wasting their battery and cpu unnecessarily and they won't like it.

-------------------------------------------------------------------------------------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to