Service or thread?


Last Updated:

  1. lian

    lian New Member This Topic's Starter

    Joined:
    Nov 15, 2009
    Messages:
    2
    Likes Received:
    0
    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
     

    Advertisement
  2. DaveInNYC

    DaveInNYC Well-Known Member

    Joined:
    Nov 7, 2009
    Messages:
    52
    Likes Received:
    3
    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.
     
  3. lian

    lian New Member This Topic's Starter

    Joined:
    Nov 15, 2009
    Messages:
    2
    Likes Received:
    0
    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?
     
  4. Droid123

    Droid123 New Member

    Joined:
    Nov 19, 2009
    Messages:
    1
    Likes Received:
    0
    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.
     

Share This Page

Loading...