• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Service or thread?

lian

Lurker
Good day.

I am a new developer in Android.

I have the following question:

I need play the background music.
What is the better, use a service, that only should play a music or the different thread in my application .


Thanks,
Lian
 
I would say service, as this is how most samples I have seen do it. The big thing is, do you want the music to still play while your app is not the currently "active" one (i.e. is running in the background?). If so, I think you would need to use a service.
 
Thanks, you for answer.

1.If I need that the background (service or thread) all the time interacts with the UI application. In this case, what the better?

2.In what case the performance will the better, in a case with a thread or a service?

3.What do the application's thread do, when the Activity is not an active state?
 
All Activities, Services and Broadcast Receivers are executed on the main thread (GUI thread).

So if you use a service to play music your entire GUI will be blocked. A solution for this is to start a new thread with a Service in it, when you start your music player.

This gave me a headache a while back since "background service" implies non-blocking operation.
 
Back
Top Bottom