I am trying to create an MP3 Player where the music carries on playing even when the app is not visible and the user has another app open. I'm not sure if I'm on the right track (no pun intended). These are the assumptions I've based my code on so far...
And last question, as my service is going to do CPU intensive work (play music) I understand that I need a new thread to do that work.
Do I create a new thread within the service to do that work, or let my activity create a new thread and run the service in that thread ?
Thanks in advance, M.
I need to use a Service to enable playing the music in the background.
Yes.
For this service its best to use a Binding Service as opposed to a Started Service.
Absolutely not. In fact, it can't be done solely using a bound service, because once the activity unbinds (e.g., in onDestroy()
), the service shuts down.
I can bind this service by Extending the Binder class (using AIDL is overkill because different I don't need different apps to access the service, only my app).
Yes.
The Service needs to be a foreground service so that its not a candidate for the system to kill when low on memory.
Yes.
my service is going to do CPU intensive work (play music) I understand that I need a new thread to do that work.
That is handled for you by MediaPlayer
automatically.
Do I create a new thread within the service to do that work, or let my activity create a new thread and run the service in that thread ?
None of that is necessary.