Global Broadcast Receiver (Android)

I have an application with several actions, and I want to receive notifications when the phone goes online (it doesnโ€™t matter which of these actions the user enters). I found a broadcast receiver to do this, but I would like to know if there is a way to announce this BroadcastReceiver only once, I want to avoid the need to place a code in each action (I have more than 20 activities!).

Thanks.

+1
source share
2 answers

Create an abstract parent class that extends Activity and define the broadcast receiver implementation there. Modify the activity classes later to extend the parent class.

+2
source

As in the documentation, if we declare a broadcast receiver in a manifest file, it automatically starts behind. The fact is that now you need to process the onReceive () method of the recipient. Another way is that you create a separate java class and import where you want.

+1
source

All Articles