Chapter 11. Broadcast Receivers

In this chapter, you will learn about broadcast receivers and when to use them. We’ll create a couple of different receivers that illustrate different usage scenarios. First, you’ll create a broadcast receiver that will start up your update service at boot time, so that users always have their friends’ latest timelines the first time they check for them (assuming their preferences are set). Next, you will create a receiver that will update the timeline when it changes while the user is viewing it. This will illustrate the programmatic registration of receivers and introduce you to broadcasting intents. We’ll implement a receiver that is trigged by changes in network availability. And finally, we’ll learn how to surround our app with some security by defining permissions.

By the end of this chapter, your app has most of the functionality that a user would need. The app can send status updates, get friends’ timelines, update itself, and start automatically. It works even when the user is not connected to the network (although of course it cannot send or receive new messages).

About Broadcast Receivers

Broadcast receivers are Android’s implementation of the Publish/Subscribe messaging pattern, or more precisely, the Observer pattern. Applications (known as publishers) can generate broadcasts to simply send events without knowing who, if anyone, will get them. Receivers (known as subscribers) that want the information subscribe to specific messages via filters. ...

Get Learning Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.