Related uses of intent in Android

Source: Internet
Author: User

Intent the first usage is to use it to jump between activities

Create a new secondactivity activity and create a new second_layout for it. The XML layout file also creates a button with the name 2. Then register in Androidmanifest.xml.

Next, rewrite the button click Time in Firstacitivity

button Click events First create a new button listener, and then override the OnClick method in the listener.

The OnClick method is intent how to display the jump activity, that is, explicitly specify which activity to jump to. Create a new intent object that completes the active jump with the StartActivity method after the purpose is defined.

This will jump to the secongactivity activity when we click the button 1 in the firstactivity activity.

Intent there is also a way to jump activity, that is, "implicit jump", or the use of implicit intent.

We first set the secondactivity activity in the Androidmanifest.xml file, that is, set what kind of implicit intent it can be.

Secondactivity This intent is only possible if <action> and <category> can match the action and category specified in intent.

Where <category> set the "Android.intent.category.DEFAULT" This is the default category, that is, if the intent does not restrict the category conditions, it will automatically use this limit

Modify the onclick () in firstactivity

Run Discovery Click Button 1 to jump to the secondactivity activity, because the action is matched, and the category that is not set is automatically set to the default, which is also matched.

If you want to set the category, you only need to call intent's addcategory () method.

Of course, you have to set an activity to match the category, or it will be an error. We still set up secondactivity this activity

It can be found that the program runs correctly and still matches the activity on secondactivity. This indicates that an activity is capable of having multiple category attributes.

Learning ' The first line of code ' 2

Related uses of intent in Android

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.