Intent can be understood to be the media between different components of Android or Messenger, play the role of communication, so that the coupling between the four components is not particularly much, the system scalability is relatively strong and robust.
We can imagine that a robot is made up of activity,service,broadcast,contentprovider, and if it is not able to "run" together, then now we have a intent that can be understood as the joint of a robot,
This communicates the four components and the robot can run. (including binder mechanism, this C/s structure to some extent is to understand the decoupling)
And the browser's URL analogy, between the client and the server by sending a URI to communicate with each other, this loose network topology will be very robust, easy to share server resources and network expansion.
Then the common use of intent is to start activity,service,broadcasst.
Component Name |
Method name |
Activity |
StartActivity () Startactivityforresult () |
Service |
StartService () Bindservice () |
Broadcasts |
Sendbroadcast () Sendorderedbroadcast () Sendstickybroadcast () |
Intent there are two ways to find the target component. One for the display call, directly specified by component name, such as startactivity (intent), two-bit implicit invocation, no explicitly specified target component name, filter filtering by certain criteria, such as Setaction
So the point is, what part of the intent object is composed, consisting of six parts: Component Name,action,data,category,extras, Flags.intent can choose several of them to construct, mainly depends on the use of intent. (Intent essence is a collection of a series of transmission information types)
1.Component Name
Component name is the component name, which is the component name to process the intent object.
The component name object is encapsulated by the ComponentName class, and the component name contains the package name and class name, which is declared in the Androidmanifest.xml file.
The component name is obtained through the getcomponent () by SetComponent (), SetClass (), Setclassname () settings.
Note that component name is an option , and if set, then the intent object explicitly specifies the component to turn to, and if it is not set, the intent object needs to filter the lookup based on other information.
2.Data
The data type can also be specified explicitly, such as the SetData () method specifies that the data is Uri,settype () specified as MIME type,setdataandtype () specifying that it is both a URI and a MIME type. Read the URI with GetData (), MIME type with GetType ().
3.Category
The method corresponding to category has add addcategory (), remove removecategory ( ), and get all category GetCategories () .
The common CATEGORY constants are: Category_browsable, category_gadget,category_home,category_launcher,category_proference.
The category is often specified by some controls.
4.Extras
In fact, data can be used as a bundle object using the Putextras () and Getextras () methods. We can see that bundles are essentially hashmap, storing some key values, and then passing information about these key values.
Public Bundle () {
MMap = new hashmap<string, object> ();
Mclassloader = GetClass (). getClassLoader ();
}
5.Flags
Various types of flag. Many are used to specify how the Android system initiates activity, and how to treat it when the activity is activated. All of these are defined in the intent class.
6.Action
An action is a string constant that intent the action to complete.
There are a number of predefined constants in the intent class, for some common actions, and others that are defined elsewhere in the Android API.
You can also define the action constants yourself, and the custom constants need to be prefixed with the package name of your app.
The action largely determines how other parts of intent are constructed, especially the data and extras domains. (as if the function name determines the value of the parameter and the return value.) So the name of the action should be as specific as possible, and they should be tightly combined with other domains in the intent.
Use Setaction () and Getaction () to set and read the Action property.
Common ACTION includes: Action_call,action_edit,action_main,action_sync,action_battery_low,
Action_headset_plug,action_screen_on,action_timezone_changed.
Action points to systems services such as System service,broadcast, which are often related to Android system services.
Android-Understanding Intent