How Android parses intent Filter

Source: Internet
Author: User

The anonymous runtime binding makes it important to understand how Android parses an implicit intent to a specific application component.

 

As you can see before, when startactivity is used, intent is implicitly parsed to a single activity. If multiple activities have the ability to execute a given action on specific data, Android will choose the best one to start.

 

Intent parsing determines which activity to run. The purpose of intent Parsing is to find the best matching intent filter through the following process:

 

1. Android puts the intent filter available in the installed package into a list.

 

2. The action and the intent filter that are not associated with the intent category being parsed will be deleted from the list.

 

2.1. Action matching means that the intent filter contains specific actions or unspecified actions. An intent filter has one or more defined actions. If no one matches the action specified by the intent, the intent filter is regarded as an action matching check failure.

 

2.2. More Strict type matching. Intent filter must contain all types defined in the parsed intent. An intent filter without a specific type can only match an intent without a specific type.

 

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

 

Intent filter with no data value specified will match all intent data.

 

3.1. mimetype is the data type of the data that is being matched. When matching data types, you can use wildcards to match child types (for example, earthquakes /*). If intent filter specifies a data type, it must match intent; if no data is specified, all match.

 

3.2. scheme is the URI Protocol-for example, http:, mailto:, tel :.

 

3.3. Host-name or "Data authority" is a part between scheme and Path in Uri (for example, www.google.com ). When the host name is matched, the scheme of the intent filter must also be matched.

 

3.4. The data path is followed by "Data authority" (for example,/ig ). The path matches only when both scheme and host-name match.

 

4. If more than one component is parsed during this process, it will be sorted with priority. You can add an optional label to the intent filter node. The component with the highest level will return.

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.