1. Download our Official Android App: Forums for Android!

Apps Service or thread?

Discussion in 'Android Development' started by lian, Nov 15, 2009.

  1. lian

    lian Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Nov 15, 2009

    Nov 15, 2009
    2
    0
    5
    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 Member
    Rank:
    None
    Points:
    16
    Posts:
    52
    Joined:
    Nov 7, 2009

    Nov 7, 2009
    52
    3
    16
    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 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Nov 15, 2009

    Nov 15, 2009
    2
    0
    5
    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 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Nov 19, 2009

    Nov 19, 2009
    1
    0
    5
    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...