Post 73: Android: Intent Filter Collision - What happens if multiple activities has the same filter name?
Intent Filter Collision
What happens if another activity (in either the same or a separate application) has the same filter name? For example, suppose your application has another activity named Activity3, with the following entry in the AndroidManifest.xml file:
If you call the startActivity() method with the following intent, then the Android OS will display a selection of activities, as shown in below figure:

If you check the “Use by default for this action” item and then select an activity, then the next time the intent “net.revan.SecondActivity” is called again, it will launch the previous activity that you have selected.
To clear this default, go to the Settings application in Android and select Apps ➪ Manage applications, and then select the application name (below see Figure). When the details of the application are shown, scroll down to the bottom and click the Clear defaults button.

What happens if another activity (in either the same or a separate application) has the same filter name? For example, suppose your application has another activity named Activity3, with the following entry in the AndroidManifest.xml file:
<?xml version=“1.0“ encoding=“utf-8“?> <manifest xmlns:android=“http://schemas.android.com/apk/res/android“ package="net.revan.UsingIntent" android:versionCode="1" android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" /> <application android:icon="@drawable/ic_launcher" android:label=”@string/app_name” >
<activity android:label=”@string/app_name” android:name=”.UsingIntentActivity” >
<intent-filter > <action android:name=”android.intent.action.MAIN” /> <category android:name=”android.intent.category.LAUNCHER” /> </intent-filter>
</activity>
<activity android:label=”Second Activity” android:name=”.SecondActivity” >
<intent-filter > <action android:name="net.revan.SecondActivity" /> <category android:name=”android.intent.category.DEFAULT” /> </intent-filter> </activity>
<activity android:label=”Third Activity” android:name=”.ThirdActivity” >
<intent-filter > <action android:name="net.revan.SecondActivity" /> <category android:name=”android.intent.category.DEFAULT” /> </intent-filter> </activity> </application> </manifest>
If you call the startActivity() method with the following intent, then the Android OS will display a selection of activities, as shown in below figure:
startActivity(new Intent("net.revan.SecondActivity"));
If you check the “Use by default for this action” item and then select an activity, then the next time the intent “net.revan.SecondActivity” is called again, it will launch the previous activity that you have selected.
To clear this default, go to the Settings application in Android and select Apps ➪ Manage applications, and then select the application name (below see Figure). When the details of the application are shown, scroll down to the bottom and click the Clear defaults button.
Comments
Post a Comment