Android Program Development: (2) use intent-2.6 Understand intent object

Source: Internet
Author: User

So far, we have learned how to use the intent object to call other activities. Next, let's talk about how intent objects are used.

1. You can pass an action to the intent constructor:

[Java] View plaincopy
    1. Startactivity (NewIntent ("Net. learn2develop. secondactivity"));

2. You can directly specify the activity component, as shown in the following figure:[Java]View plaincopy

    1. Startactivity (NewIntent (This, Secondactivity.Class));

3. You can pass an action constant and data to the intent object:[Java]View plaincopy

    1. Intent I =NewIntent (Android. content. Intent. action_view, Uri. parse (Http://www.amazon.com"));
    2. Startactivity (I );

The action part defines "what do you want to do", and the data part includes the data to be executed by the target activity. You can also pass data to the intent object through the setdata () method:[Java]View plaincopy

    1. Intent I =NewIntent ("Android. Intent. Action. View");
    2. I. setdata (URI. parse (Http://www.amazon.com"));

In the preceding example, the webpage to be accessed is specified through a specific URL. Then, the android system looks for the activities that meet the requirements. This process is called "intent Parsing ".

For some intents, there is no need to set data. For example, to select a contact from the contacts application, you can set the action and use the settype () method to set the MIME type:

[Java] View plaincopy
    1. Intent I =NewIntent (Android. content. Intent. action_pick );
    2. I. settype (contactscontract. Contacts. content_type );

The settype () method explicitly specifies the MIME data type, and also indicates the type of returned data. The MIME type of contactscontract. Contacts. content_type is "Vnd. Android. cursor. DIR/contact ".

In addition to specifying action, Data, type, an intent object, you can also specify a category. CATEGORY divides activities into "logical units", so that the Android system can use category for "long-term" filtering. The next tutorial will detail the category attributes.

To sum up, an intent object can contain the following information:

    • Action
    • Type
    • Data
    • Category

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.