


OnStop() or onPause():- These methods are used for unregistering a broadcast receiver of the activity. This method is called by the Android system. Receive broadcast app has to extend the BroadcastReceiver abstract class and override the onReceive() method. Statically (manifest-declared) - This receiver can be registered via the AndroidManifest.xml file.ĭynamically (context-registered) - This registers a receiver dynamically via the Context.registerReceiver() method. There are two different methods to register a broadcast receiver. Broadcast receivers helps our app communicate with Android OS and other apps.īasic Concepts of Broadcast Receivers Register Broadcast: Here the term intent is actually a broadcast, and if a broadcast receiver is registered in the manifest file or code to listen to these events, then it will respond to these broadcast intents.Īndroid OS sends broadcasts to apps when any event happens in the app or in the system. So, whenever these kinds of events happen, an intent is triggered. You register this broadcast receiver either in the manifest file or in the code. The listener is nothing but a broadcast receiver. To listen to these events you will need a listener which will only listen to particular events for which it is registered. These events are low battery, wifi availability, incoming call, bluetooth device connected, incoming SMS, charger (connected or disconnected), and others.įor example, in the case of a low battery event, you want to stop your app from using any backend data polling mechanism.

There are many different types of Android events that we may encounter in which we use a broadcast receiver.
