Regular Intents vs Broadcast Intents

Things are happening all the time on an Android device. WiFi is going in and out of range, packages are getting installed, and phone calls and text messages are coming and going.

There may be many components on the system that need to be aware of these kinds of events so that they can react accordingly. To notify these components, Android uses a broadcast intent to tell everyone about it.

These kinds of broadcasts, which are sent from the system, are referred to as system broadcasts, but you can also send and receive your own custom broadcasts. The mechanism for receiving both system and custom broadcasts is identical, but you will only be working with custom broadcasts in this chapter.

Broadcast intents work similarly to the intents you already know and love, except that they can be received by multiple components, called broadcast receivers, at the same time (Figure 28.1).

Figure 28.1  Regular intents vs broadcast intents

Regular intents vs broadcast intents

Activities and services should respond to implicit intents whenever they are used as part of a public API. When they are not part of a public API, explicit intents are almost always sufficient. Broadcast intents, on the other hand, only exist to send information to more than one listener. So while broadcast receivers can respond to explicit intents, they are rarely, if ever, used this way, because explicit intents can only have one receiver.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.234.234