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

Can anyone tell me when to use intent filter and broadcast receiver?

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

      

and

<receiver>
      <intent-filter></intent-filter>
 </receiver>

      

+3


source to share


2 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 is off, the battery is low, or a picture has been taken. Applications can also initiate broadcasts - for example, so that other applications know that some data has been downloaded to the device and is available for use. Although broadcast receivers do not display a user interface, they can create a status bar notification to alert the user when a broadcast event occurs. However, the broadcast receiver is simply a "gateway" to other components and is designed for a minimum amount of work. For example, it can trigger to do some event based work.

You can use a broadcast receiver in two ways.

1) Registration and deregistration of your activities. When you register with your activity, you need to pass the action for which it takes care, and it fires when we broadcast with this action from our application.

2) The second way to use a broadcast receiver is to register in the manifest file and specify the action in the intent filter for the manifest file.



Intent filter is just simple words "This is the filter that we use in our everyday life." It will filter actions to call it.

The intent filter is the same for activity and broadcast receiver. The main function is action filtering. It is up to us how to use it. One of the main examples in our every application in the manifest file we specify

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

      

in our launch activities. This assumes this activity is our launch activity and will be launched at the beginning of our application. If you do not specify it, then your application will not start. Also we cannot specify these types of filters in the broadcast receiver intent filter. They don't launch applications

+4


source


I think you are confused about implicit intent and broadcast receiver. Intent Filter in Activity is for receiving implicit intent, while in Receiver for receiving broadcast. The OS delivers the broadcast protocol to all recipients, while it provides an implicit intent for a specific action. See here



+2


source







All Articles