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