有兩個應用:A.apk和B.apkandroid
1.A經過componentName去訪問B的主Activityspa
ComponentName cn=new ComponentName("com.myandroid.test","com.myandroid.test.MainActivity");//包名,主Activitycomponent
Intent intent=new Intent();xml
intent.setComponent(cn);it
startActivity(intent);io
2.A經過componentName去訪問B的非主Activitytest
須要在B的AndroidManifest.xml中爲指定的非主Activity添加屬性exported="true"margin
<activity android:name="com.myandroid.test.OtherActivity" exported="true"/>activity
調用代碼同1.filter
3.A訪問B的非主Activity
B:<activity android:name="com.myandroid.test.OtherActivity">
<intent-filter>
<action android:name="android.intent.action.xml" />
<data android:scheme="info" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
A:Intent intent = new Intent("com.myandroid.test",Uri.parse("info://OtherActivity"));
startActivity(intent);
【若是出現兩個Activity的action和category和data相同時,會出現選擇】