Use of Android Development Series (10) Intent

Source: Internet
Author: User

In this section, I do not want to continue with Android interface development. Instead, I want to talk about Intent. Later, I may make the QQ login interface and chat interface, however, the chat interface may be considered after I have reviewed the Sqlite database, but I should record the content of this section for future reference.

 

Intent is used to start an Activity, Service, or BroadCast.

1. You can use setClass or set the original Activity or target Activity in the constructor to display the specified jump object.

 

 

2. You can also use the setAction method to set the Action attribute (a string) for the Intent object, and then start intent. intent-filter of Activity registration information in xml automatically filters objects that meet the conditions.

Note:

The newly created Activity must be in AndroidManifest. if <intent-filter> </intent-filter> is not registered in xml, you only need to configure the name. However, if intent-filter exists, it must contain

<Action/> and <category/> attributes. The category attribute of a common Activity can be <category android: name = "android. intent. category. DEFAULT"/>.

/***** Example *****/

AndroidManifest. xml

<Intent-filter>

<Action android: name = "Action information"/>

<Category android: name = "android. intent. category. DEFAULT"/>

</Intent-filter>

 

MainActivity. java

Intent intent = new Intent ();

Intent. setAction ("Action Inforation ");

StartActivity (intent); // note that the form of Action Information here is arbitrary, but it must not conflict with other activities

/****************/

 

3. You can use addCategory to set category to further limit the Activity to be started.

AndroidManifest. xml

<Intent-filter>

 

<Action android: name = "Action information"/>

  

<Category android: name = "TSIDJ"/>

<Category android: name = "android. intent. category. DEFAULT"/>

 

</Intent-filter>

 

MainActivity. java

Intent intent = new Intent ();

Intent. setAction ("Action Inforation ");

Intent. addCategory ("TSIDJ ");

StartActivity (intent );

// Note that the addCategory () attribute indicates that an additional attribute is added. Note: 1. The DEFAULT attribute of categeory cannot be omitted; 2. category cannot jump to an Activity independently, but Action can jump to an Activity independently. category is only used as an additional condition, that is, if the action/data information is the same and the category information is different, the Activity cannot be started.

 

Let's write so much today. We should have a rest early ..

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.