Technology10/14/2019

BroadcastReceiver

Sponsored Intelligence Dispatch






What is Broadcast Receivers?

Broadcast Receivers is an Android implementation of system-wide publish/subscribe mechanism.

The receiver is simply a dormant code that gets activated once an event it is subscribed to happens.

The system itself broadcasts events all the time. For example, when an SMS arrives, or call comes in, or battery runs low, or system gets booted, all those events are broadcasted and any number of receivers could be triggered by them.


You can also send your own broadcasts from one part of your application to another, or a totally different application.

Broadcast receivers themselves do not have any visual representation nor are they actively running in memory. But when triggered, they get to execute some code, such as start an activity, a service, or something else what we defined.



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.


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 takemore time, do not do heavy database operations or networking operations in broadcast receiver.

Deep Structural Diagnostics.

Mastering JSON is only the first step. Use our industrial-grade workbench to format, validate, and synthesize models for your production APIs.

Sponsored Infrastructure

Industrial Analysis Active