Data, Type
The Data property is used to provide the action attribute to the Action property. The Data property accepts a URI (format such as: Scheme://host:port/path) object.
The Type property is used to specify the MIME type that corresponds to the URI specified by data, and the MIME format is: abx/xyz
Declares that the data and type attributes are set by the <data.../> element, in the following format:
<data
Android:mimetype=""
Android:scheme=""
android:host=""
Android:path=""
android:port=""/>
The matching rules are as follows:
1. If intent specifies the type attribute, the activity will be started only if the mimetype of <data.../> in <intent-filter.../> is the same as the value of type
2. If you do not specify a type attribute and only specify the data property, the matching rule is as follows:
If scheme is specified in activity-only <data.../>, then the intent in the data value as long as the scheme is the same as in the activity, the other host, port, path no matter how much, can start the activity.
There are also Scheme+host, Scheme+host+port, Scheme+host+path and the above matching process, as long as the intent value is the same as the <data.../> value of activity, but does not specify the host, Specifying port and path alone is not working.
As an example:
The following is a list of the <data.../> properties of 5 activity in Androidmanifest.xml, hereinafter referred to as A1,A2,A3,A4,A5.
<ActivityAndroid:name=". Datatypeattr "Android:label= "@string/title_activity_data_type_attr"> <Intent-filter> <ActionAndroid:name= "Android.intent.action.MAIN" /> <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> </Intent-filter> </Activity> <ActivityAndroid:icon= "@drawable/ic_scheme"Android:name=". Schemeactivity "Android:label= "Activity of the specified scheme"> <Intent-filter> <ActionAndroid:name= "XX" /> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> <!--as long as the intent Data property scheme is Lee, you can start the activity - <DataAndroid:scheme= "Lee" /> </Intent-filter> </Activity> <ActivityAndroid:icon= "@drawable/ic_host"Android:name=". Schemehostportactivity "Android:label= "Activity of the specified scheme, host, port"> <Intent-filter> <ActionAndroid:name= "XX" /> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> <!--as long as the intent Data property scheme is Lee, and host is www.fkjava.org, Port is 8888 to start the activity - <DataAndroid:scheme= "Lee"Android:host= "www.fkjava.org"Android:port= "8888" /> </Intent-filter> </Activity> <ActivityAndroid:icon= "@drawable/ic_sp"Android:name=". Schemehostpathactivity "Android:label= "Activity of the specified scheme, host, path"> <Intent-filter> <ActionAndroid:name= "XX" /> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> <!--as long as the intent Data property scheme is Lee, and host is www.fkjava.org, path is/mypath to start the activity - <DataAndroid:scheme= "Lee"Android:host= "www.fkjava.org"Android:path= "/mypath" /> </Intent-filter> </Activity> <ActivityAndroid:icon= "@drawable/ic_path"Android:name=". Schemehostportpathactivity "Android:label= "Activity of the specified scheme, host, port, path"> <Intent-filter> <ActionAndroid:name= "XX" /> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> <!--The scheme that requires the data property of intent is Lee, and host is www.fkjava.org, Port is 8888, and path is/mypath to start the activity - <DataAndroid:scheme= "Lee"Android:host= "www.fkjava.org"Android:port= "8888"Android:path= "/mypath"/> </Intent-filter> </Activity> <ActivityAndroid:icon= "@drawable/ic_type"Android:name=". Schemehostportpathtypeactivity "Android:label= "Activity to specify scheme, host, port, path, type"> <Intent-filter> <ActionAndroid:name= "XX"/> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> <!--The scheme that requires the data property of intent is Lee, and host is www.fkjava.org, Port is 8888, and path is/mypath, and type is abc/x YZ to start the activity - <DataAndroid:scheme= "Lee"Android:host= "www.fkjava.org"Android:port= "8888"Android:path= "/mypath"Android:mimetype= "ABC/XYZ"/> </Intent-filter> </Activity>
The following will give 5 intent, hereinafter referred to as I1,I2,I3,I4,I5. First of all, only A5 has mimetype, and the following intent only i5 contains mimetype attribute, because A5 can only be started by i5, and the other 4 attributes are equal, so A5 could be i5 started. Looking at the other, A1, only the scheme attribute is Lee, so the scheme attribute of I1,i2,i3,i4 is Lee, so A1 can be i1,i2,i3,i4 started. a2,scheme=lee,host=www.fkjava.org,port=8888, can be started by I2,I4. A3,scheme=lee,host=www.fkjava.org,path=/mypath, can be started by I3,I4. The A4 can only be started by I4.
Public voidScheme (View source) {Intent Intent=NewIntent (); //set the Data property of intent onlyIntent.setdata (Uri.parse ("Lee://www.crazyit.org:1234/test")); StartActivity (Intent); } Public voidSchemehostport (View source) {Intent Intent=NewIntent (); //set the Data property of intent onlyIntent.setdata (Uri.parse ("Lee://www.fkjava.org:8888/test")); StartActivity (Intent); } Public voidSchemehostpath (View source) {Intent Intent=NewIntent (); //set the Data property of intent onlyIntent.setdata (Uri.parse ("Lee://www.fkjava.org:1234/mypath")); StartActivity (Intent); } Public voidSchemehostportpath (View source) {Intent Intent=NewIntent (); //set the Data property of intent onlyIntent.setdata (Uri.parse ("Lee://www.fkjava.org:8888/mypath")); StartActivity (Intent); } Public voidSchemehostportpathtype (View source) {Intent Intent=NewIntent (); //also set the data, type property of the intentIntent.setdataandtype (Uri.parse ("Lee://www.fkjava.org:8888/mypath") , "ABC/XYZ"); StartActivity (Intent); }
Extra Property
The value is a bundle object that can be deposited into multiple key-value pairs so that data can be exchanged between different activity through intent.
Flag Property
The flag attribute is mainly used to control some activities of activity when the activity is started, and the specific role is further studied.
At present, in addition to the role of component and extra properties have a clearer understanding of the other 4 is still not clear, follow-up needs to be further studied.
Android Development Intent (2)