Introducing Broadcasts and Receivers

To date, we have focused on one type of Android component: the activity. There are actually four different types of components. App widgets are based on another component: the BroadcastReceiver.

You might think that a BroadcastReceiver receives broadcasts. In truth, it does, but the story is a bit more complex than that.

In Android, we can “broadcast” an Intent. Instead of using startActivity(), we use sendBroadcast(). An Intent that is broadcast could be very generic, in which case it might be truly “broadcast” to a variety of apps on the device that are set to receive such a broadcast. Nowadays, more commonly, the Intent is an explicit Intent, identifying a particular component that should receive it. While technically this is still termed a “broadcast”, only that designated component will receive it, not any arbitrary app.

Normal Android user interfaces are created by activities, perhaps with the assistance of fragments. In contrast, app widget user interfaces are created using a BroadcastReceiver. Android will send a special broadcast to our BroadcastReceiver, telling us to provide the UI definition. That UI definition is then passed along to the home screen, which will render that UI for us.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.