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 cla开发者_StackOverflow社区ss 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 receiverThanks, Shraddha
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
精彩评论