显式 Intent 调用
1 //创建一个显式的 Intent 对象(方法一:在构造函数中指定) 2 Intent intent = new Intent(Intent_Demo1.this, Intent_Demo1_Result1.class); 3 4 Bundle bundle = new Bundle(); 5 bundle.putString("id", strID); 6 intent.putExtras(bundle); 7 8 intent.putExtra("name", "bbb"); 9 intent.putExtra("userInfo", new UserInfo(1, "name")); 10 startActivity(intent); 11 12 //创建一个显式的 Intent 对象(方法二:用 setClass 方法) 13 Intent intent = new Intent(); 14 Bundle bundle = new Bundle(); 15 bundle.putString("id", strID); 16 intent.setClass(Intent_Demo1.this, Intent_Demo1_Result1.class); 17 intent.putExtras(bundle); 18 startActivity(intent); 19 20 //创建一个显式的 Intent 对象(方法三:用 setClass 方法) 21 Intent intent = new Intent(); 22 Bundle bundle = new Bundle(); 23 bundle.putString("id", strID); 24 intent.setClassName(Intent_Demo1.this, "com.great.activity_intent.Intent_Demo1_Result1"); 25 intent.putExtras(bundle); 26 startActivity(intent); 27 28 //创建一个显式的 Intent 对象(方法四:用 setComponent 方法) 29 Intent intent = new Intent(); 30 Bundle bundle = new Bundle(); 31 bundle.putString("id", strID); 32 //setComponent方法的参数:ComponentName 33 intent.setComponent(new ComponentName(Intent_Demo1.this, Intent_Demo1_Result1.class)); 34 intent.putExtras(bundle); 35 startActivity(intent);
Intent隐式跳转 Action
1 //创建一个隐式的 Intent 对象:Action 动作 2 /** 3 * 这里指定的是 AndroidManifest.xml 文件中配置的 4 * <intent-filter>标签中的<action android:name="com.great.activity_intent.Intent_Demo1_Result3" /> 5 * 所在的 Activity,注意这里都要设置 <category android:name="android.intent.category.DEFAULT" /> 6 */ 7 Intent intent = new Intent(); 8 //设置 Intent 的动作 9 intent.setAction("com.great.activity_intent.Intent_Demo1_Result3"); 10 Bundle bundle = new Bundle(); 11 bundle.putString("id", strID); 12 intent.putExtras(bundle); 13 startActivity(intent);
AndroidManifest.xml
1 <activity android:name="Intent_Demo1_Result3" 2 android:label="Intent_Demo1_Result3"> 3 <intent-filter> 4 <action android:name="com.great.activity_intent.Intent_Demo1_Result3" /> 5 <category android:name="android.intent.category.DEFAULT" /> 6 </intent-filter> 7 </activity>