Android Broadcast Receivers

Saranya N
2 min readAug 10, 2017

--

Broadcast Receiver in Android — In our series of Android articles, Previously we discussed about Services , Activity and Fragment

Android Broadcast Receiver is one of the principal components of Android application development. Broadcast receiver which is also known as receiver is a component of android application. With this component we can register receivers for any system-level or application-level event. Once that event occurs, android system will notify the registered receivers about the execution of events respectively.

Types of Broadcasts

There are two types of broadcasts received by receivers and they are:

1. Normal Broadcasts:

  • These are asynchronous broadcasts.
  • Receivers of this type of broadcasts may run in any order, sometimes altogether.
  • This is efficient.
  • Receivers cannot use the result.
  • They cannot abort the included APIs.
  • These broadcasts are sent with Context.sendBroadcast

2. Ordered Broadcasts

  • These are synchronous broadcasts.
  • One broadcast is delivered to one receiver at a time.
  • Receivers can use the result. In fact as each receiver executes, result is passed to next receiver.
  • Receiver can abort the broadcast and hence no broadcast is received by other receivers.
  • The order of receivers is managed and controlled by the attribute android:priority in corresponding intent-filter.
  • If receivers will have same priority then they may run in any order.

Take a quick Glance at : Top 25 Android Interview Questions and Answers

Benefits of Broadcast Receiver

  • A Broadcast receiver wakes your application up, the inline code works only when your
    application is running.
  • No UI but can start an Activity
  • It has maximum limit of 10secs, do not do any asynchronous operations which may take
    more time, do not do heavy database operations or networking operations in broadcast
    receiver.

Check out : Advanced Android Topics

Also Read : Skills and Responsibilities you need to be an Android Devleoper

--

--