I. Basic points of knowledge
1, <activity android:label= "The first activity" android:name= ". Main2activity "/>
Label Property: The title of a acivity
2. The r file should not be wrongly cited as the bottom of Android.
3, Intent.setclass (this, main2activity.class);
First parameter: Context
Second parameter: Bytecode file for the component to be activated
4, explicit activation (explicitly specified to activate the component)
1) Intent.setclass (this, main2activity.class);
2) Intent.setclassname (this, "com.njupt.multiactivity.Main2Activity");
Second parameter: The full class name of the component that needs to be opened
3) Intent.setclassname (Getpackagename (), "Com.njupt. multiactivity. Main2activity ");
Getpackagename (): Gets the value of the package property under the <manifest> node in the Androidmanefest
4) Intent.setcomponent (new ComponentName (this, main2activity.class));
5) Intent Intent = new Intent (this,main2activity.class);
5, <button
android:onclick= "Open"/>
Multiple controls can fire the same event handler, the Open function fired here
6, implicit intent activation (before activating the browser or anything like this is done)
1) <activity android:name= ". Main3activity "android:label=" 闅 radiation marl Sleepsac Kuang Chairman Wilson Trajectory Chan € wa meat crypto activity ">
<intent-filter >
<action android:name= "Com.njuptThe name of the. Action.main3 "/>//action can be easily picked up
<category android:name= "Android.intent.category.DEFAULT"/>//this must have, otherwise will error. The above is the mini configuration
<category android:name= "Com.njupt. categroy.main3 "/>//doesn't make much sense, adding this line wouldn't have much effect.
<data android:scheme= "Itcast" android:mimetype= "Image/jpeg"/>
</intent-filter>
</activity>
The action, category, and data are configured in the Androidmanifest.xml and must be set in the code.
Specify an action name
Intent.setaction ("cn.itcast.action.main3");
Setting up data
Intent.setdata (Uri.parse ("Itcast:"));
Set Mime_type
Intent.settype ("Image/jpeg");//will automatically clear the data, so this should be changed to
Intent.setdataandtype (Uri.parse ("Itcast:"), "image/jpeg");
7. The type of mimetype can be found in Tomcat (Conf/web.xml)
8. Open the browser with implicit intent
Intent Intent = new Intent ();
Intent.setaction ("Android.intent.action.VIEW");
Intent.setdata (Uri.parse ("http://www.baidu.com"));
startactivity (intent);
Ii. examples
1, Mainactivity
Package Com.example.multiactivity;import Android.net.uri;import Android.os.bundle;import android.app.Activity; Import Android.content.componentname;import Android.content.context;import Android.content.intent;import Android.view.menu;import Android.view.view;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main);} public void open (view view) {int id = View.getid (); if (id = = R.ID.OPEN1) {/** * below shows the 5 ways of showing activation *///Intent Intent = new Intent ();//Intent.setclass (this, Mainactivity2.class);//Intent.setclassname (this, "com.example.multiactivity.MainActivity2");// System.out.println ("---------->" + getpackagename ());//Intent.setclassname (Getpackagename (), " Com.example.multiactivity.MainActivity2 ");//Note that the second parameter is a full-class name//Intent.setcomponent (new ComponentName (This, Mainactivity2.class)); Intent Intent = new Intent (this, mainactivity2.class); StartActivity (Intent); }else if (id = = r.id.open2) {Intent Intent = new Intent (); Intent.setaction ("hellointent");//Intent.setdata (Uri.parse ("Zhangzetian:"));//Intent.settype ("Image/jpeg"); Intent.setdataandtype (Uri.parse ("Zhangzetian:"), "image/jpeg"); StartActivity (Intent); }else if (id = = R.id.open3) {Intent Intent = new Intent (); Intent.setaction (("Android.intent.action.VIEW")); Intent.setdata (Uri.parse ("http://www.baidu.com")); StartActivity (Intent); }} @Overridepublic Boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is Present.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}
2, MainActivity2
Package Com.example.multiactivity;import Android.app.activity;import Android.os.bundle;public class MainActivity2 Extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main2);}}
3, MainActivity3
Package Com.example.multiactivity;import Android.app.activity;import Android.os.bundle;public class MainActivity3 Extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main3);}}
4, in the process of explicit activation and implicit intent activation, in fact, the Androidmanifest.xml file is very important. So I enclose all the code of Androidmanifest.xml here:
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" Com.example.multiactivity "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-s DK android:minsdkversion= "8" android:targetsdkversion= "/>" <application android:allowback Up= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" Android:theme= "@style /apptheme "> <activity android:name=" com.example.multiactivity.MainActivity "Android:la Bel= "@string/app_name" > <intent-filter> <action android:name= "android.intent.action . MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-filte r> </activity> <activity android:name= "Com.example.multiactivity.MainActivity2" Android:label= "This is a second activity." /> <activity android:name= "Com.example.multiactivity.MainActivity3" > < Intent-filter > <action android:name= "hellointent"/> <category android:name= "and Roid.intent.category.DEFAULT "/> <category android:name=" asdasd "/> <data android: Scheme= "Zhangzetian" android:mimetype= "Image/jpeg"/> </intent-filter> </activity > </application></manifest>
Third, the source code download:
http://download.csdn.net/detail/caihongshijie6/7792167