A brief talk on the intent of Android

Source: Internet
Author: User

We all know that the implementation of Android programs are generally composed of four components:

    1. Activity:android program implements the main body of the function, provides the interface with the customer interaction, also provides the function which interacts with the background.
    2. Service: is a non-interface activity, mainly used in the background to run the program.
    3. Broadcast: is a tool for communication between the current program and the system.
    4. Contentprovider:android Program, a tool for managing resources.

The above 4 components need to be registered in manifest to be able to use, manifest is equivalent to the Android program of the Big Butler. Of course, light has not enough components, to realize the data (or resources) between components and components of the transfer, without a key "people", that is the intent class. As for what is intent? I will briefly introduce you to the following.

First, what is intent?

Intent this word means "purpose, intention" in English. What do you mean by putting it in a computer? Simply put, the Android system establishes a mechanism to assist in the delivery and communication of data (or resources) between applications. So how do you pass it? Don't worry, Android has created a class for this, which is intent. You can think of it as a bridge or a link between applications and the data interaction between the above 4 components. So its intentions are obvious, that is, the transfer of data (resources).

Intent is also a runtime binding mechanism in the program, which means that it can connect any two different components while the program is running. With intent, you can make requests to the Android system, and the Android system responds by selecting the appropriate component based on your request content.

Another reason to use intent to establish a connection is to reduce the degree of coupling between programs. (coupling refers to a dependency between two applications)

Ii. three ways to create intent:

1. Intent Intent = new Intent (starting Component object, target Component class. Class)

2. Intent Intent = new Intent ()

Intent.setclass (Start Component object, Target Component object. Class)

3. Get the Intent object passed from the previous activity (Intent = Getintent ())

Third, some member variables (or attributes) included in the intent class

1.mComponent (Destination component): It is the type of componentname, which is the package name of the source and target components that make the jump between components, used for display. It explicitly specifies the class name of the intent target component. This component includes the package name and the class name, and must be declared in the manifest file.

2.mAction (Action): it represents the action of an operation and is a string constant. It is a default string that is predefined in advance, which is to let the current activity be the entry for the project, and it needs to be set in the Intent-filter tag in the manifest file.

3.mCategory (category): The category of the component being launched. A intent can contain more than one category description of the information. It is important to note that in the manifest file, both the action and category are registered, and they are generally used together, and in the code, the default category must be used if no category is specified.

4.mData (data): This parameter is the data of the URI type storage operation, such as: The URL to visit, call, etc., the role is to provide action to the action data. The so-called URI is the Uniform Resource Identifier (including:/HTTP, hostname, resource index value;), and the Android framework system defines the URI class to handle the data that the intent object is working on.

5.mType (data type): Displays the specified data type (MIME). The data type of the general intent can be judged according to the data itself, but by setting this property, you can force the display of the specified type to be no longer inferred. Generally the front is a large type followed by a small type.

The type attribute can only be named MimeType in the XML file: (for example)


1 <Intent-filter>2                 <ActionAndroid:name= "Com.jaoco.SECOND_ACTIVITY" />3                 <categoryAndroid:name= "Android.intent.category.DEFAULT" />4                 <Data5                     Android:scheme= "http"6 Android:host= "Www.jaovo.com"7 Android:path= "/android"8 Android:port= "8090"9 Android:mimetype= "Image/png"Ten                     /> One             </Intent-filter>

Method for setting the value of the Type property: public void SetType (String type)

Method for setting data and Type property values: public void Setdataandtype (Uri uri,string type) If you want to set both data and type values, use this method only. Because both Settype () and SetData () are set to NULL by default.

6.mExtras (Extended information): All data that is carried in the intent class is wrapped in this class.

7.mFlags (flag bit): It is a pattern that expects the intent to run.




A brief talk on the intent of Android

Related Article

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.