Android Learning Intent Learning Notes

Source: Internet
Author: User

1 introduce the method of activation intent in code:

Show activation Intent//Method 1//intent intent=new Intent ();//intent.setclassname ("Com.example.multiactivity", " Com.example.multiactivity.SecondActivity ");//startactivity (intent);//Method 2//intent Intent=new Intent (this, Secondactivity.class);//startactivity (intent);////Method 3//intent intent=new Intent ();//componentname component2=new ComponentName (this, com.example.multiactivity.SecondActivity.class);//componentname component=new componentname (" Com.example.multiactivity "," com.example.multiactivity.SecondActivity ");//(" Com.example.multiactivity ", Secondactivity.class);//intent.setcomponent (component2);//COMPONENT1/2 can//startactivity (intent);//implicit activation intent// Intent intent=new Intent ();//intent.setaction ("Com.example.multiactivity.SecondActivity3");//intent.addcategory ( "Android.intent.category.DEFAULT");//Interpreter XML fileStartActivity (intent);//implicit intent to activate the system comes with function intent intent=new intent ();  Intent.setaction (Intent.action_call);   Intent.setdata (Uri.parse ("Tel:" + "15607209140")); StartActivity (Intent);

  

  

2 In addition to activating the system's own intent, the user-defined intent needs to be defined in the manifest file:

 <application android:allowbackup= "true" android:icon= "@drawable/ic_            Launcher "android:label=" @string/app_name "android:theme=" @style/apptheme "> <activity Android:name= "com.example.multiactivity.MainActivity" android:label= "@string/app_name" > <i ntent-filter> <action android:name= "Android.intent.action.MAIN"/> <category and                        Roid:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity  Android:name= ". Secondactivity " 
            android:label= "secondactivity" >             <intent-filter>                <action Android:na Me= "com.example.multiactivity.SecondActivity"/>                <action android:name= " Com.example.multiactivity.SecondActivity2 "/>                <action android:name=" Com.exam Ple.multiactivity.SecondActivity3 "/>                      <category android:name=" Android.intent.category.DEFAULT "/>            </intent-filter>                    </activity>            </application>

The red part is the custom activity

1 Here is your own definition of the activity,name tag is the activity's name, "." Represents the package name, followed by the class name, if the name is preceded by a package name program will be an exception, and automatically generated above the activity plus the package name does not appear abnormal, it may be customary.

2 implicit activation, the name of the action can be multiple, any match can be, but must register the category tag content, in the program using Intent.addcategory (), or the program will also appear abnormal.

Android Learning Intent Learning notes

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.