Reputation: 13
I am going one activity to another using an explicit Intent and I declare it in the manifest file.
<activity
android:name=".Activity2"
android:label="Activity 2">
<intent-filter
action android:name="com.tr.ACTIVITY2"
category android:name=”android.intent.category.DEFAULT">
</intent-filter>
</activity>
It works fine but one book uses intent-filter
for this and I am confused about when we use intent filter.
Upvotes: 1
Views: 4064
Reputation: 156
When you use an explicit intent it's like you tell Android "open Activity2".
When you use an implicit intent you tell Android: "open an activity that can do these things". these things is actually the filter that you write in the manifest for Activity2.
As an example, if you are in Activity1 and want to start Activity2:
You can have explicit:
Intent intent = new Intent(Activity1.this, Activity2.class);
startActivity(intent);
Or implicit:
Intent intent = new Intent();
intent.addAction("myAction");
intent.addCategory("myCategory");
startActivity(intent);
And in this case you should have in your manifest file something like:
<activity android:name=".Activity2">
<intent-filter>
<action android:name="myAction"/>
<category android:name="myCategory"/>
</intent-filter>
</activity>
Upvotes: 14