Android Intent Filter analysis, androidintent

Source: Internet
Author: User

Android Intent Filter analysis, androidintent

In Activity and Service, Intent represents a request to execute actions on a dataset. Intent Filter declares that a specific application component can operate on a type of data.

To register an Acitivty or service as a possible Intent handler, you can add an intent-filter tag to its mainfest node and use the following tag.

  • Action uses the android: name attribute to specify the name of the action to be served. Each Intent Filter must have at least one action tag, and action should be a descriptive and unique string. Therefore, the best practice is to use a naming system based on the Java package name conventions.
  • Category uses the android: name attribute to determine under which circumstances the service should be provided for the action. Each Intent Filter tag can contain multiple category tags, which can be used to define its own tags, you can also use the following Android labels:

    • ALTERNATIVE can specify this action as an option for executing the default action on a specific data type. For example, the default action of a contact is to view its information, and the optional action is to edit it.
    • SELECTED_ALTERNATIVE is similar to ALTERNATIVE, but ALTERNATIVE always uses the intent resolution described later to parse it into an action. If there are many possibilities required in the second step, SELECTED_ALTERNATIVE can be used.
    • BROWSABLE specifies an action available inside the browser. When an Intent is triggered inside the browser, it will always contain the BROWSABLE category. If you want an application to respond to the actions triggered inside the browser, such as intercepting links to a specific website, it must contain the BROWSABLE category.
    • By setting this type, DEFAULT can use a component to become the DEFAULT action of the specified data type in the Intent Filter. This type is necessary for activities that use a realistic Intent automatically.
    • HOME you can set the category of an Intent Filter to HOME without specifying an action.
    • LAUNCHER uses this category to make an Activity appear in the auto-Starter of the application Chen Xu.
  • The data tag allows you to specify the data types that can be executed by a component. You can use any combination of attributes to specify the data supported by your component:

    • Android: Create a valid host name, such as google.com.
    • Android: mimetype specifies the data type that can be executed by the component. For example, it matches all Android cursor
    • Android: path indicates the valid URL value of the URI, for example,. transport/boats/
    • Android: port indicates a valid window for the host.
    • Android: scheme requires a specific mode such as content or http
How Android parses Intent Filter

When an implicit Intent is passed in startActivity, the process of deciding which Activity to start is called Intent parsing. The purpose of intent Parsing is to use the following steps to find the most matched Intent Filter.

  1. Android puts available Intent filters of installed packages into a list
  2. Intent filters that do not match the action or category associated with parsing Intent will be removed from the list.
    • If the Intent Filter contains the specified action, you can think that the action matches. If no action is found to match the action specified by the Intent, the action match fails.
    • For a category match, the Intent Filter must contain all category in the Intent to be parsed, but can contain other category not included in the Intent, an Intent Filter without a category can only match an Intent without any category.
  3. Each part of the Intent data URI is compared with the data tag of the Intent Filter. If the Intent Filter specifies the scheme, host/authority, path, or MIME type, these values must be compared with the Intent URI. If any one of them does not match, the Intent Filter will be removed from the list, intent Filter with no data value is matched with all Intent data values, which is different from category.

    • The MIME type is the data type of the data to be matched. When the data type is matched, wildcards can be used to match the child type, such as earthquake /*. If Intent Filter specifies a data type, it must match the Intent. If no data type is specified, it will match all Intent
    • Scheme is the URI protocol, such as http: tel:
    • Hostname or data authority is the part where URI is located between scheme and path. For example, if developer. android. name and hostname are to be matched, the scheme of Intent Filter must also be matched.
    • The data path is the content after authority, such as/training. The path can be matched only when the scheme and hostname of the data match.
  4. When an Activity is started implicitly. If multiple components are parsed, all components that may match are displayed to the user.

Transfer responsibility

You can use the startNextMatchingActivity method to pass the responsibility for processing the action to the next best matching Activity.

Intent intent = getIntent();if(ifDuringBreak){startNextMatchingActivity(internt);}


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.