1. Are you ready for the Galaxy S20? Here is everything we know so far!

Service implementation doubts

Discussion in 'Android Development' started by mobileprogram, Sep 6, 2011.

  1. mobileprogram

    mobileprogram Lurker
    Thread Starter

    I'm facing a design question. I'm coding an app to read content sites( video, news, etc ). Each of these contents is handled by a specific activity. So far so good. I've find out the Service class and I will use it to monitor my internet connection implementing some methods to monitor. But because my monitoring will occurs for all activities I don't know how I can do this. If I use ServiceConnection for all activies is wrong because in the first time the connection is established. So, is it a good solution to pass the ServiceConnection object for other activies when they are created?

    Thanks for replies

    1. Download the Forums for Android™ app!


  2. alostpacket

    alostpacket Over Macho Grande?

    Welcome to the forums :)

    You may want to use BroadcastReceiver(s) in your activities. You can set them up to receive special intents sent by your service, or register them to listen for the connection change intent that the OS sense out.

    using these in your activities, you can register them in onResume() and unregister them in onPause()

    this way you will have only one activity that is litening for the intent at any given time.

    hope that helps

Share This Page