Yossi wrote:
> Is it possible to keep service alive even if the foreground app does
> not run anymore?

Yes, for a while anyway.

> My app consists of a foreground app (UI) and a service that should
> keep running in the background until it is being explicitly stopped by
> the user (similar to a music player). The problem is that if the user
> opens other apps, my foreground app is being killed by the system
> (makes sense) but then also the service is being killed by the system
> (does not make sense).
> 
> Can I change that? Is it related to the way I start/bind/unbind to the
> service?

Since we have none of your code, it is difficult to say whether code
changes will help.

Android will shut down your service, if it needs the memory. However,
this comes only after all background activities are closed up.

It is possible you have a memory leak (e.g., closing up your activities
did not release their RAM). Or, it is possible you are using
bindService() -- after all bound activities are shut down, Android might
consider the service eligible to be shut down. There may be other
possibilities as well.

You might also consider whether your service truly needs to be in memory
all the time (few do) and whether you are better served using
AlarmManager to arrange for background work to be done on a periodic basis.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Warescription: Three Android Books, Plus Updates, $35/Year

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

Reply via email to