2

I have an application which tells the state of the device (Connected/Disconnected). Now I have registered the Broadcast Receiver for the same and display the appropriate state.
1. But my problem is that I have to make this status message common to all the activities. So where do I register this receiver and where do I unregister the receiver. I dont want the repeatative code. So is there any place from which I can do an common register and unregister instead of unregistering it in every activity for onDestroy().
Can I use the Application class in any way so as to have an common place to register and unregister?
Or is the Manifest file appropriate in my case to register the receiver

Thanks, Shraddha

Shraddha Shravagi
  • 1,096
  • 1
  • 9
  • 22

1 Answers1

1

Android provides BroadcastReceivers, which can be independent of an Activity. These can be "registered" in your applications manifest. Of course, you need a corresponding programmed receiver to which the manifest corresponds when the suitable intent is called.

See here: http://developer.android.com/guide/topics/manifest/intent-filter-element.html

Jonathan Roth
  • 1,271
  • 1
  • 12
  • 19
  • Thanks for your valuable help Jonathan Can you please give me link of any example for the same? – Shraddha Shravagi Aug 22 '11 at 12:37
  • an example can be found here: http://stackoverflow.com/questions/5725417/restrict-broadcast-receiver-to-application your programmed receiver must extend BroadcastReceiver http://developer.android.com/reference/android/content/BroadcastReceiver.html – Jonathan Roth Aug 22 '11 at 12:49
  • I have registered the Receiver in the xml as follows. – Shraddha Shravagi Aug 23 '11 at 11:56