1

As per the android documentation, we can define a priority for the intent-filters in the Manifest file. The priority can be a integer with 0 being a default value. Also if we check the setPriority(int Priority) API, while describing the priority it says Positive values will be before the default, lower values will be after it.

What does having negative priority value here implies, and how is it useful? I have seen many libraries using -1 as a priority for intent filters in their Manifest file.

Twisha Kotecha
  • 1,082
  • 1
  • 4
  • 18
Tulika
  • 625
  • 1
  • 8
  • 23

1 Answers1

1

Negative values indicate that these intent filters would have a lower priority. The lesser the value for android:priority the lesser is the priority given when delivering an intent(ex: a broadcast ).

Ex : Consider that there is a broadcast, ex: Install Receiver Broadcast. You app is listening to the broadcast. An SDK that you have used in the app is also listening to the same broadcast(priority set to -1). When the broadcast is broadcasted, your app receiver would receive it first and the SDK would receive it second. This is because your receiver by default would have a priority set to 0.

This is mostly done by SDK's because those SDK's want to give priority for the app to handle their custom logic.

This attribute has meaning for both activities and broadcast receivers: It provides information about how able an activity is to respond to an intent that matches the filter, relative to other activities that could also respond to the intent. When an intent could be handled by multiple activities with different priorities, Android will consider only those with higher priority values as potential targets for the intent. It controls the order in which broadcast receivers are executed to receive broadcast messages. Those with higher priority values are called before those with lower values. (The order applies only to synchronous messages; it's ignored for asynchronous messages.) Use this attribute only if you really need to impose a specific order in which the broadcasts are received, or want to force Android to prefer one activity over others. The value must be an integer, such as "100". Higher numbers have a higher priority. The default value is 0.

Dinesh
  • 948
  • 6
  • 11
  • But if lets say I make use of such an SDK and use a second SDK which defines a default priority, then the first SDK using a negative priority is letting the other SDKs intervene first. How would that be useful? – Tulika Oct 24 '19 at 04:52
  • If those intents are critical to the functioning of the SDK's they would define a higher priority. The fact that they define a lower priority means that its not critical to the functioning of the SDK. Also the SDK's would have given you a clearly defined integration process in such cases. – Dinesh Oct 24 '19 at 04:58