Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between intent filter in activity and broadcast receiver?

Can anybody tell me when should I use intent filter and broadcast receiver?

<activity>
          <intent-filter></intent-filter>
</activity>

and

<receiver>
      <intent-filter></intent-filter>
 </receiver>
like image 693
Chandi Gorom Avatar asked Oct 29 '25 08:10

Chandi Gorom


1 Answers

From the documentation:

A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. Applications can also initiate broadcasts—for example, to let other applications know that some data has been downloaded to the device and is available for them to use. Although broadcast receivers don't display a user interface, they may create a status bar notification to alert the user when a broadcast event occurs. More commonly, though, a broadcast receiver is just a "gateway" to other components and is intended to do a very minimal amount of work. For instance, it might initiate a service to perform some work based on the event.

You can use broadcast receiver by two ways.

1) Registering and un-registering in your activity.When you register with your activity you need to pass an action for which it will take care and it will fire when we send broadcast with that action from our application.

2) Second way to use broadcast reciver to register in manifest file and mention action in intent filter for that in manifest file.

Intent filter is nothing but in simple words "It is filter just we use in our usual lives." It will filter the actions for calling it.

Intent filter is same for activity and broadcast receiver.Its main functioning is to filtering the action.It depends on us how to utilize it.One major example is in our each application in manifest file we specify

<intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

in our launcher activity.It suggests this activity is our launcher activity and will run first at start of our application.If you not specify it then your application will not launch.Also we can not specify these types of filter in broadcast receiver's intent filter.They are not launcher of apps,

like image 81
Jay Shah Avatar answered Oct 30 '25 23:10

Jay Shah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!