Pages

Ads 468x60px

Saturday 6 July 2013

Resolving Intent Filter Collision

Resolving Intent Filter Collision

In the previous lesson , you learned that the <intent-filter> element defines how your activity can be invoked by another activity. 
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.learn2develop.Activities”
android:versionCode=”1”
android:versionName=”1.0”>
<application android:icon=”@drawable/icon” android:label=”@string/app_name”>
<activity android:name=”.MainActivity”
android:label=”@string/app_name” >
<! -- android:theme=”@android:style/Theme.Dialog” -- >
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
<activity android:name=”.Activity2”
android:label=”Activity 2”>
<intent-filter>
<action android:name=”net.learn2develop.ACTIVITY2” />
<category android:name=”android.intent.category.DEFAULT” />
</intent-filter>
</activity>
<activity android:name=”.Activity3”
android:label=”Activity 3”>
<intent-filter>
<action android:name=”net.learn2develop.ACTIVITY2” />
<category android:name=”android.intent.category.DEFAULT” />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion=”9” />
</manifest>

If you call the startActivity() method with the following intent, then the Android OS will display
a selection as shown in Figure :

startActivity(new Intent(“net.learn2develop.ACTIVITY2”));

If you check the “Use by default for this action” item and then select an activity, then the next time the intent “net.learn2develop.ACTIVITY2” is called again, it will always launch the previous activity that you have selected.

To clear away this default, go to the Settings application in Android and select Applications 
➪ Manage applications and select the application name (see Figure). When the details of the application are shown, scroll down to the bottom and click the Clear defaults button.



 

0 التعليقات:

Post a Comment

.

Education blog