Every Android application may run in its own process and has an independent Dalvik Virtual Machine instance. Android is a large system with hundreds of megabytes of data, each part has an organic relationship and is only available for everyone to learn and think about.
Intent describes the actions, actions involving data, and additional data of an application. Android identifies the corresponding components based on the description of the Intent, pass Intent to the called component and complete the call of the component. Therefore, Intent acts as a media intermediary here, providing information about component calls to each other to decouple callers from callers.
For example, in an application maintained by a contact, when we assume the corresponding Activity is listActivity on the screen of a contact list, click a contact, you want to jump out of the contact's details page and assume that the corresponding Activity is detailActivity)
To achieve this purpose, listActivity needs to construct an Intent, which is used to tell the system that we want to perform the "View" action. The corresponding viewing object of this action is "a contact ", call startActivity (Intent intent ),
The constructed Intent is passed in. The system will find the Activity that meets the Intent requirements in ManiFest according to the description in this Intent. The system will call the Activity that is found, that is, detailActivity, and finally pass in the Intent, detailActivity performs the corresponding operation based on the description in the Intent.
In the Android reference document, Intent is defined as an abstract description of an operation ). Let's take a look at the abstract description. First, it is a brief description of the action to be executed, such as VIEW_ACTION view) and EDIT_ACTION modification. Android defines a set of standard actions for us:
- MAIN_ACTION
- VIEW_ACTION
- EDIT_ACTION
- PICK_ACTION
- GET_CONTENT_ACTION
- DIAL_ACTION
- CALL_ACTION
- SENDTO_ACTION
- ANSWER_ACTION
- INSERT_ACTION
- DELETE_ACTION
- RUN_ACTION
- LOGIN_ACTION
- CLEAR_CREDENTIALS_ACTION
- SYNC_ACTION
- PICK_ACTIVITY_ACTION
- WEB_SEARCH_ACTION
In addition, we can also define our own actions based on the needs of the application, and define the corresponding Android Application to process our custom actions. Secondly, is the data to be operated by the action ). Android uses a URI pointing to data. For example, in a contact application, a URI pointing to a contact may be:
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.notepad
- ">
- <application android:icon="@drawable/app_notes"
- android:label="@string/app_name">
-
- <provider class=".NotePadProvider"
- android:authorities="com.google.provider.NotePad
- " />
-
- <activity class=".NotesList" android:label="@string/title_notes_list">
- <intent-filter>
- <action android:value="android.intent.action.MAIN" />
- <category android:value="android.intent.category.LAUNCHER" />
- </intent-filter>
- <intent-filter>
- <action android:value="android.intent.action.VIEW" />
- <action android:value="android.intent.action.EDIT" />
- <action android:value="android.intent.action.PICK" />
- <category android:value="android.intent.category.DEFAULT" />
- <type android:value="vnd.android.cursor.dir/vnd.google.note
- " />
Android app, additional information of the executed action. For example, LAUNCHER_CATEGORY indicates that the receiver of Intent should appear as a top-level application in Launcher, while ALTERNATIVE_CATEGORY indicates that the current Intent is one of a series of optional actions that can be executed on the same piece of data.
Type), explicitly specify the Intent data type MIME ). Generally, the Intent data type can be determined based on the data itself. However, by setting this attribute, You can forcibly use the explicitly specified type instead of derivation.
Specifies the Class Name of the Intent's target component. Generally, Android searches for other attributes in Intent, such as action, data/type, and category. Finally, find a matched target component. However, if this attribute of component is specified, the component specified by component will be used directly without executing the above search process. After this attribute is specified, all other Intent attributes are optional.