‫I'll create a new var intent filter.
‫It's of type intent filter equals to intent filter and I name it as Android dot intent, dot action
‫dot airplane underscore mode.
‫What is intent filter A broadcast receiver is associated with one or more intent filters.
‫An intent filter is a set of criteria such as action, category, and data that specifies the types
‫of broadcasts the receiver should listen to.
‫When a broadcast matches the criteria specified in the intent filter, the all receive method of the
‫receiver is called.
‫So in order to call the and trigger this function inside the airplane mode receiver, I need to match
‫the intent filter, which is of type an action airplane mode.
‫Then I need to create an instance of the airplane mode receiver.
‫So var airplane mode receiver it's of type broadcast receiver new or airplane mode receiver.
‫I'm creating an instance of this broadcast receiver that we created before.
‫Now I need to call register receiver function.
‫I'll pass airplane mode receiver and the intent filter register receiver function or method is used
‫to dynamically register a broadcast receiver in your application code.
‫This method is typically called within an activity, service, or other context where you want to receive
‫broadcasts.
‫In this case, I'm calling it inside the main activity.
‫Also, I need to call Ondestroy method and use Unregister receiver and pass the airplane mode receiver.
‫I'll name it like this because I need to create it as global.
‫So I'll remove this var and I'll make it as late initiate.
‫Okay, I created like this I initialize it in the Oncreate method and here I unregister the receiver.
‫It's important to unregister the receiver in the Ondestroy method to avoid memory leaks.
‫This ensures that the receiver is unregistered when the activity is destroyed.
‫Let's run our application and here our application.
‫Now I'm going to switch the airplane mode to on here I click on it on again I'll switch it to on and
‫you can see airplane mode toast telling us that it is on.
‫I'll change this length to long in order to display it clear.
‫Now let's run our application.
‫And here I'll switch the airplane mode to off.
‫And you can see airplane mode is off.
‫Toast message displayed back to on and airplane mode is on.
‫This is how we'll listen for any changes in the system.
‫A broadcast receiver is an Android component that allows the registration and handling of system wide
‫broadcast messages.
‫It enables communication between different parts of the Android application or between different applications.