"Android first line code" learning record 03-switching activities using intent

Source: Internet
Author: User

The use of intent is divided into two categories:

I. Using an explicit intent

The explicit intent is to explicitly provide the current context and the context in which to jump the activity when instantiating intent, as shown in the following code:

New Intent (mainactivity.  this, otheractivity. class ); startactivity (intent);

Second, the use of implicit intent

Implicit intent does not explicitly specify which activity to start, but rather by specifying the action and category, which activity is initiated by system analysis, in the following steps:

1, registered in the Androidmanifest.xml is initiated activities

<ActivityAndroid:name=". Otheractivity ">    <Intent-filter>        <ActionAndroid:name= "Com.xxx.yyy.ACTION_START" />        <categoryAndroid:name= "Android.intent.category.DEFAULT" />        <categoryAndroid:name= "Com.xxx.yyy.zzz" />    </Intent-filter></Activity>

2. Instantiate intent in the keynote activity and add category to intent

New Intent ("Com.xxx.yyy.ACTION_START"); Intent.addcategory ("com.xxx.yyy.zzz"); StartActivity (Intent) ;

More usages of implicit intent

By implicit intent, it makes it possible to start the activities of other applications, such as

1. Start the browser to open the Web page:

New Intent (Intent.action_view); Intent.setdata (Uri.parse ("http://www.baidu.com/")); StartActivity ( Intent);

2. Start dialing:

New Intent (intent.action_dial); Intent.setdata (Uri.parse ("tel:10086")); StartActivity (Intent) ;

"Android first line code" learning record 03-switching activities using intent

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.