Android analyzes the method of Intent Filter

  • 2020-06-23 01:58:56
  • OfStack

An example of Android illustrates the method of Intent Filter parsing. Share to everybody for everybody reference. The specific analysis is as follows:

The anonymous nature of runtime binding makes it important to understand how Android resolves 1 implicit Intent to 1 specific application component.

As you saw before, when using startActivity, the implicit Intent resolves to a single 1 Activity. If there are more than one Activity capable of performing a given action on a particular piece of data, Android will choose the best of these to start.

The process of deciding which Activity to run is called Intent parsing. The purpose of Intent parsing is to find the best possible match for Intent Filter through the following process:

Place the Intent Filter available in the installed package into a list.

2. Actions and Intent Filter that are not associated with the type of Intent being parsed will be removed from the list.

. Action matching means that Intent Filter contains specific actions or actions that are not specified. An Intent Filter has one or more defined actions. If none of the actions can match the actions specified by Intent, the Intent Filter counts as an action match check failure.

. The type matching is more strict. Intent Filter must contain all classes defined in the parsed Intent. An Intent Filter without a specific type can only be matched with an Intent without a specific type.

3. Finally, Intent's data parts in URI are compared with data tags in Intent Filter. If Intent Filter defines scheme, host/authority, path or mimetype, these values are compared to URI of Intent. Any mismatch will cause Intent Filter to be removed from the list.

Intent Filter with no data value specified matches 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 1 data type, it must match Intent; All matches if no data is specified.

. scheme is the agreement of part URI -- for example, http:, mailto:, tel:.

3. host-name or "data authority" is the part between scheme and path in URI (for example, www.google.com). When the host name is matched, Intent Filter's scheme must also pass the match.

. Data path is immediately after "data authority" (e.g. /ig). path matches only if both scheme and ES110en-ES111en parts match.

4. If more than one component is resolved during the process, they will be sorted by priority, and an optional tag can be added to the node of Intent Filter. The highest level component returns.

The Android native application component and the third party application 1 sample are both part of the Intent parsing process. They have no higher priority and can be completely replaced by the new Activity, which claims that its Intent Filter responds to the same action request.

I hope this article has been helpful for your Android programming.


Related articles: