Android parsing method of intent filter

This article describes the method of Android parsing intent filter. Share with you for your reference. The specific analysis is as follows:

The anonymous nature of runtime binding makes it important to understand how Android parses an implicit intent to a specific application component. As you saw before, when using startactivity, the implicit intent resolves to a single activity. If there are multiple activities that can perform a given action on specific data, Android will choose the best one to start. The process of deciding which activity to run is called intent parsing. The purpose of intent parsing is to find the best matching intent filter through the following process: 1. Android puts the available intent filters in the installed package into a list.

2. The action and the intent filter not associated with the type of intent being parsed will be deleted from the list.

① . action matching means that the intent filter contains specific actions or no specified actions. An intent filter has one or more defined actions. If none of them can match the actions specified by intent, the intent filter will be regarded as an action matching check failure. ② . species matching is more strict. The intent filter must contain all the categories defined in the resolved intent. An intent filter without a specific category can only match an intent without a category.

3. Finally, the data URI of intent will be compared with the data tag in intent filter. If intent filter defines scheme, host / authority, path or mimeType, these values will be compared with intent URI. Any mismatch will cause intent filter to be removed from the list.

An intent filter that does not specify a data value will match all intent data.

① . mimeType is the data type of the data being matched. When matching data types, you can use wildcards to match subtypes (for example, earthquakes / *). If intent filter specifies a data type, it must match intent; If no data is specified, all match. ② . scheme is the protocol of the URI part -- for example, http:, mailto:, Tel:. ③ . host name or "data authority" is the part of the URI between scheme and path (for example, www.google. Com). When matching the host name, the scheme of intent filter must also pass the matching. ④ . data path is immediately after "data authority" (for example, / Ig). Path matches only if both the scheme and host name parts match.

4. If more than one component is resolved in this process, they will be sorted by priority. You can add an optional label in the intent filter node. The highest level component will return.

Android native application components, like third-party applications, are part of the intent parsing process. They have no higher priority and can be completely replaced by new activities. These new activities declare that their intent filter can respond to the same action request.

I hope this article will be helpful to your Android program design.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>