JDS
JDS

Reputation: 16988

Android - what is a foreground service? (vs regular service)

Right now I have some class myService extends Service() being called by a startService intent from another context. The service runs some code in onStartCommand and then is destroyed/killed.

What exactly is a 'foreground' service and how is it created? Does it last longer than other services?

If so that would be ideal because I'm tinkering around with a music player in my service that I would want to play in the background and have control of. The issue right now is that my service gets created and destroyed multiple times, so I end up starting too many instances of the music player and lose control of the original one.

Thanks.

Upvotes: 5

Views: 1064

Answers (1)

mah
mah

Reputation: 39807

A foreground service is one that, for example, plays music -- something the user would immediately notice if it were killed. Android will favor non-foreground services for killing if system memory gets low, but it can still kill a foreground service if needed.

Upvotes: 6

Related Questions