Android----Intent Detailed

Source: Internet
Author: User

The role of 1.Intent for Android apps

It can be broadly divided into two functions:

① packaged Android applications need to start the "intent" of a component

② acts as a medium for communication between application components, encapsulates the data that needs to be exchanged into bundle objects, and then uses intent to carry the bundle object

2.Intent Object 2.1 Using intent to start system components

Start activity:startactivity (Intent Intent)

Startactivityforresult (Intent intent,int requestcode)

Start Service:componentname StartService (Intent Intent)

Boolean Bindservice (Intent service,serviceconnection conm,int flags)

Start Broadcastreceiver:sendbroadcast (Intent Intent)

Sendbroadcast (Intent intent,string recepermission) etc

2.2 Intent properties and Intent-filter configuration

Intent represents the intention of an Android app to launch an app, and the Android app will launch the specified component according to intent.

As for which component to start, it needs to be judged by the value of the property that is not understood.

2.2.1 Component Properties

The concept of a component is introduced first: including Service (services), activity (activities), content (contents),

Intent (intention), Broadcastrece (broadcast), Notification (notice)

The component (ingredient) attribute of intent accepts a value called ComponentName, and the componentname structure is:

Component (String pkg)//create all components corresponding to the CLS class under the package that contains the PKG

Component (String pkg,string CLS)//component corresponding to the CLS class under the package corresponding to the creation of the PKG

Component (String pkg,class CLS)//component corresponding to the CLS class under the package corresponding to the creation of the PKG

They are all based on the Baoming and the class name to determine a component and then start it

Also available through Intent's SetClass (context Package,class CLS), Setclassname (context packagecontext,string className)

Setclassname (Strong packagename,string ClassName) to specify the component to be started by this intent

This explicit designation of which component to start is called explicit intent and there is an implicit intent for the component that starts the kimono rule according to the rules.

For example

?
12345678910 HelloWorld1.javaIntent intent = new Intent();ComponentName component = new ComponentName(HelloWorld1.this,HelloWorld2.class);intent.setComponent(component);startActivity(intent); HelloWorld2.javaComponentName component = getIntent().getComponent();//可以通过Intent获取Component的值

2.2.2 Action, category attribute, and Intent-filter configuration

Intent's action, category property is a normal string in which the action represents an abstract action to be done by the intent, and the category is used to

Add additional nearby category information for the action. The action is usually used in combination with the Category property.

What is the value of the action and category in the configuration information for an activity or other component? Usually includes 0~n child elements

0~n child elements and 0~1 child elements. This is quite a condition for a sister to find a tender friend.

When the action and category of the intent are all satisfied with the action and category of the component, the component is opened, which is the equivalent of a boy who fully satisfies her sister.

Conditions were together.

Generally, intent will typically specify only one action, but you can specify multiple category

2.2.3 Specify action, category invoke system activity

Action and Category table click to open link

2.2.4 Data, type attribute, and Intent-filter configuration

The data property is typically used to provide manipulation data to the Action property, which accepts a URI object, usually represented by a string of the following form:

?
12 content://com.android.contacts/contacts/1tel:123

The URI string satisfies the following format:

Scheme://host:port/path

Content is the scheme part, Com.android.contacts is the host part, the port part is omitted,/CONTACTS/1 is the path part

The Type property is used to specify the MIME type that corresponds to the URI specified by the data, which can be any custom MIME type.

As long as the string conforms to the ABC/XYZ format.

The type and data properties sometimes overwrite each other, for example: intent sets the data property before setting the Type property, and Tpye overwrites the data

property, and vice versa. The workaround is to set the call Setdataandtype () method

corresponding to setting the Type,data property value in the Androidmainifest.xml file by element

Element supports the following properties:

MimeType: The type attribute used to declare the intent that the component matches

Scheme: The scheme part that declares the data property of the component's matching intent

Data: The host part of the data property used to declare the intent that the component matches

Host: The host part of the data property used to declare the intent that the component matches

Port: The port portion of the data property used to declare the intent that the component matches

Path: The path portion of the data property used to declare the intent that the component matches

Pathprefix: The path prefix used to declare the data property of the intent that the component matches

Pathpattern: path string template for declaring the data property of the intent that the component matches

The type must be fully compliant when the component is started, but the data value of the intent is only part of the set, and only the part that satisfies the setting will be able to start.

2.2.5 Extra Properties

The extra property of intent is typically used to exchange data between multiple actions, and intent's extra attribute value should be a Bnudle object, Bundle

object is a map object that can be stored in many pairs of key-value values

2.2.6 Flag Property

The Flag property is used to add some extra control to the intent flag, and you can call the Addflags () method to add a control flag to the intent

The corresponding table of the flag attribute click the Open link

2.3 Creating tab pages with intent

The content under the different tab page is an activity

?
123456789101112131415161718 TabHost tabHost = getTabHost();TabHost.addTab(tabHost.newTabSpec("tab1")                      .setIndicator("已接电话")                      .setContent(new Intent(this,HelloWorld1.class)                                       )                       );TabHost.addTab(tabHost.newTabSpec("tab2")                      .setIndicator("未接电话")                      .setContent(new Intent(this,HelloWorld2.class)                                       )                       );TabHost.addTab(tabHost.newTabSpec("tab3")                      .setIndicator("呼出电话")                      .setContent(new Intent(this,HelloWorld3.class)                                       )                       );

A companion tour, a free dating site: www.jieberu.com

Push family, free tickets, scenic spots: www.tuituizu.com

Android----Intent Detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.