Download the New LearnVern Android App and enter Lucky Draw to win Free Certificate
If you are facing any issue in playing video please use Firefox browser.
We have seen that Intent is is 'intention to do', which means that what our activity is going to do is being decided by Intent. Now inside Intent, we use the Intent filter in Android.
Intent filters are the components that decide the behavior of intent, in our manifest file we have an activity tag, so what is going to be the work of that activity tag, we will specify it in Intent filters.
<activity android:name"". MainActivity"">
Intents are matched against intent filters not only to discover the target component to activate but also to discover something about the set of components on the device.
Let us take a situation that we are using our phone, when we click the 'home' button we get all our application on our display, then when we click on a specific icon and the very first activity which we see in that particular application is because of ACTION_MAIN action and CATEGORY_LAUNCHER category.
When we use our phone we have to deal with different types of situations, like incoming calls, our messages, our phone's battery status, etc... This all is nothing but Broadcast Receiving.
Broadcast receiving is because of two things, System generated and Application generated.
When we talk about system generated, it means it is coming from the system itself, for example 'Your phone's battery is low!' or 'Battery is fully charged.
Now when we see application-generated broadcast receiver, we see that we get different notifications from our different applications, like when we download a song.
Static way in which the broadcast receiver is registered in an Android application via AndroidManifest.xml file.
Another way of registering the broadcast receiver is dynamic, which is done using Context.registerReceiver() method.
When we talk about dynamic broadcasting, as it is user generated we have to also and register it otherwise it will leak. So for the unregistering dynamic broadcast receiver, we will use Context.unregisterReceiver() method.
Implement on Receive()
A Broadcast receiver extends broadcast receiver abstract class, which means that we have to implement the onReceive() method of this base class.
For example, if you register for ACTION_POWER_CONNECTED event then whenever power is supplied to the device your broadcast receivers onReceive() method will be invoked.
The onReceive() method takes two arguments.
onReceive(Context context, Intent intent)
Have a friend to whom you would want to share this course?