Hi Mark,

My code is relatively simple

public void onResume()
{
        Intent intent = new Intent(this, TrackingService.class);
        startService(intent);
        bindService(intent, _connection, Context.BIND_AUTO_CREATE);
}

public void onPause()
{
        if(shouldStopService())
        {
                unbindService(_connection);
                stopService(new Intent(this, TrackingService.class));
        }
}

I saw the the following in the log - INFO/ActivityManager(56): Low
Memory: No more background processes.
My service tracks the user so it should be on until the user stops
recording.
How come the system does not close the music service? Is there a
priority?

Thanks,
Yossi


On Jul 19, 1:35 pm, Mark Murphy <[email protected]> wrote:
> 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 [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