Search code examples
androidintentfilter

Why Label Intent Filters?


Just getting my hands around intent filters, and I've noticed a rather hit and miss approach to labeling intent-filters using android:label in both sample code and other online sources, yet haven't been able to find a definitive explanation for the purpose of labeling.

Can anyone point me in the right direction?

Thanks,

Paul


Solution

  • Basic example:

    • You have an app that opens text files (an activity with intent filters to do so)
    • There are more than one app to do so.
    • When the user opens a text file it will be presented with an options menu which allows him/her to decide which activity to use in order to open the text file.
    • The string you put in android:label for the intent filter is the string that the user will see in the alternatives menu.

    It's explained in the official documentation:

    A user-readable label for the parent component. This label, rather than the one set by the parent component, is used when the component is presented to the user as having the capability described by the filter.

    The label is set as a reference to a string resource so that it can be localized like other strings in the user interface. However, as a convenience while you're developing the application, it can also be set as a raw string.

    The default value is the label set by the parent component. If the parent doesn't specify a label, the default is the label set by the <application> element's label attribute.