Intent can be used to launch components and carry data that acts as a medium for communication between components.
The intent object roughly contains component, Action, Category, Data, Type, Extra, and Flag7 properties.
The following will be said separately.
Component
Component can start specific components by specifying the package name and the class name. Therefore, intent, which explicitly specifies the component property, is also known as an explicit intent. Examples are as follows:
// Create a ComponentName object New ComponentName (fromactivity. this, toactivity. class New Intent (); // Set component property for intent intent.setcomponent (comp); startactivity (intent);
Because the package name corresponds to context one by one, the constructor for passing in the context parameter is also provided in ComponentName.
Action
as follows, set the action to "xxx", and if an activity contains code in Androidmanifest.xml that is shaped like code 2, you can start the activity with code 1. You can specify only one action per intent. In addition, if the category is not set, "Android.intent.category.DEFAULT" is used by default, so you need to join the <category in code 2 Android:name= "Android.intent.category.DEFAULT" />
Code 1
// Create a Intent object New Intent (); // set the Action property for intent (the property value is a normal string)intent.setaction ("xxx"); startactivity (intent);
Code 2
< Intent-filter > < android:name= "xxx"/> <android:name = "Android.intent.category.DEFAULT"/></intent-filter >
Category
Use Intent.addcategory ("xxx"), and then add <category android:name= "xxx" to Androidmanifest.xmlactivity's registration, using the same method as the action > can. Unlike action, a intent can contain multiple category values, and the intent can only initiate an activity that joins all the category values that the intent contains at the time of registration.
Android Development Intent (1)