The Rules for Resolving Intents to Their Components

So far, we have discussed a number of aspects about intents. To recap, we talked about actions, data URIs, extra data, and finally categories. Given these aspects, Android uses the following algorithm to resolve the intents to activities.

At the top of the hierarchy, with an air of exclusivity, is the component name attached to an intent. If this is set, then every other aspect or attribute of the intent is ignored and that component is chosen for execution.

Android then looks at the action attribute of the intent. If the intent indicates an action, then the target activity must list that action as part of its intent-filter. If no other attributes are specified, then Android invokes this activity. If there are multiple activities, Android will present the activity chooser.

Android then looks at the data portion of the intent. If the intent specifies a data URI, the type is retrieved from this URI via ContentProvider.getType() if it is not already supplied in the intent. The target activity must indicate through an intent-filter that it can handle data of this type. If the data URI is not a content URI or the data type is not specified, then the URI scheme is taken into account. The target activity then should indicate that it could handle the URIs of this type of scheme.

Android then looks at the category. Android will only pick activities matching that category. As a result, if the intent category is specified, then the target activity should declare this category in its intent-filter.

0 0

Post a comment