Explain the filtering and matching process of intent object and intent filter in Android

If you don't know much about intent, please refer to the blog post "explain the usage of intent in Android", which introduces the action, category and data to be used in this article in detail. If you want to know about the common use of intent in development, please refer to intent idioms in Android.

This article is a little long. I hope you can finish it patiently.

When describing the intent filter registered by components in the manifest, it is uniformly represented by intent filter.

1、 Overview

As we know, intent is divided into two types: explicit intent and implicit intent. If an intent explicitly specifies the complete class name of the component to be started, it is an explicit intent, otherwise it is an implicit intent. When we start a component with an explicit intent, Android will directly find the component to be started according to the component name provided by the intent object. When we start a component with an implicit intent, the Android system cannot directly know the name of the component to be started. This article explains how the Android system finds the matching component to be started according to the implicit intent.

When the Android system receives an implicit intent to start an activity (or other component), Android will compare the information of the intent with the information of the intent filter of the registered component according to the following three information, so as to select the most matching activity (or other component) for the intent:

That is, the implicit intent object should meet the information in the < action / >, < category / >, and < data / > tags of the intent filter registered in the target component to be started, that is, it should pass the action test, category test, and data test respectively. The intent filter information is described in the Android manifest file. As the name suggests, intent filter is an intent filter, which is used to filter intent.

If the implicit intent object passes the action test, category test and data test of intent filter in a component at the same time, the component can be started by the intent object. If the implicit intent object does not pass the intent filter test of any component in the system, there is no android system, and the component to be started by the intent object cannot be found. Let's take a look at how to pass these three tests in turn.

2、 Action test

In order to specify the type of intent that can be received and processed, the component can declare in the intent filter that it supports 0 or more actions, for example:

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
分享
二维码
< <上一篇
下一篇>>