O'Reilly logo

Learning Android, 2nd Edition by Masumi Nakamura, Marko Gargenta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13. 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 set up the alarms to autostart your refresh timeline service every so often.

Next, you will create a receiver that will be notified when there’s a new tweet, and post that notification to the user.

In this chapter, in addition to using broadcast receivers, you will also learn how to take advantage of Android’s OS system services.

By the end of this chapter, your app will have 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. If the message matches a filter, the subscriber is activated (if it’s not already running) and notified of the message.

As you may recall from Broadcast Receivers, a BroadcastReceiver is a piece of code to which an app ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required