What is BroadcastReceiver and when we use it?

Android

Android Problem Overview


What is a BroadcastReceiver? What are its uses and how can I use it?

Android Solutions


Solution 1 - Android

Start by reading the documentation. Also, copying from Application Fundamentals:

> Broadcast receivers > > A broadcast receiver is a component that responds to system-wide > broadcast announcements. Many > broadcasts originate from the > system—for example, a broadcast > announcing that the screen has turned > off, the battery is low, or a picture > was captured. Applications can also > initiate broadcasts—for example, to > let other applications know that some > data has been downloaded to the device > and is available for them to use. > Although broadcast receivers don't > display a user interface, they may > create a status bar notification to > alert the user when a broadcast event > occurs. More commonly, though, a > broadcast receiver is just a "gateway" > to other components and is intended to > do a very minimal amount of work. For > instance, it might initiate a service > to perform some work based on the > event. > > A broadcast receiver is implemented as a subclass of > BroadcastReceiver and each broadcast > is delivered as an Intent object. For > more information, see the > BroadcastReceiver class.

Finally, read in Common Tasks how you can utilize BroadcastReceivers to listen for messages and set alarms.

Solution 2 - Android

A broadcast is generated by android on occurrence of some action , BroadcastReceiver class enables the developer to handle the situation on occurence of the event/action . Action can be arrival of msg or call , download complete , boot completed , etc.

Solution 3 - Android

Broadcast Receivers simply respond to broadcast messages from other applications or from the system itself. These messages are sometime called events or intents. For example, applications can also initiate broadcasts to let other applications know that some data has been downloaded to the device and is available for them to use, so this is broadcast receiver who will intercept this communication and will initiate appropriate action.

Solution 4 - Android

I like this slide, because it focuses on Broadcast Receiver and offers simple description. The minor problem is that the updated date was a little bit old ( in 2011 ).

enter image description here

Android Application Component: BroadcastReceiver Tutorial

(retrieved from the slide)

Broadcast Receiver

  • Receives and Reacts to broadcast Intents

  • No UI but can start an Activity

  • Extends the BroadcastReceiver Base Class

Solution 5 - Android

BroadCastReciever is an Android Component that helps you to know handle registered System Events or Application Events.

For Example:

System Events Such us : the screen has turned off, the battery is low, or a picture was captured.

Applications can also initiate broadcasts—for example, to let other applications know that some data has been downloaded to the device and is available for them to use... etc

Solution 6 - Android

In simple terms

A broadcast receiver is basically an interface that you can implement so that your app can subscribe to system changes like when the system has finished booting, or a charger is connected/disconnected or airplane mode is switched on/off etc.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBytecodeView Question on Stackoverflow
Solution 1 - AndroidkgiannakakisView Answer on Stackoverflow
Solution 2 - AndroidpriView Answer on Stackoverflow
Solution 3 - AndroidMuhammed ThasneemView Answer on Stackoverflow
Solution 4 - AndroidkenjuView Answer on Stackoverflow
Solution 5 - AndroidAdarshView Answer on Stackoverflow
Solution 6 - AndroidRick Royd AbanView Answer on Stackoverflow