Search code examples
androidandroid-intentintentfilter

What is the purpose of android:priority tag?


What is the purpose of android:priority in <intent-filter>? Because I noticed that when there is an implicit intent which can be handled by (at least) two apps, a selector (called also disambiguation dialog) appears with the possibility to choose one of the two apps. But I thought that when app_1 has an higher priority (e.g. 999) than app_2 (e.g. 0 or 10), Android would always choose app_1 without a selector.


Solution

  • The priority that should be given to the parent component with regard to handling intents of the type described by the filter. 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.

    In certain circumstances the requested priority is ignored and the value is capped to 0. This occurs when:

    A non-privileged application requests any priority >0 A privileged application requests a priority >0 for ACTION_VIEW, ACTION_SEND, ACTION_SENDTO or ACTION_SEND_MULTIPLE