Reputation: 27
Refer to the documentation on IntentFilters:
To pass this test, the action specified in the Intent object must match one of the actions listed in the filter. If the object or the filter does not specify an action, the results are as follows:
If the filter fails to list any actions, there is nothing for an intent to match, so all intents fail the test. No intents can get through the filter.
On the other hand, an Intent object that doesn't specify an action automatically passes the test — as long as the filter contains at least one action.
In my code,
Intent intent = new Intent();
startActivity(intent);
<activity
android:name=".MainActivity2"
android:label="@string/title_activity_main_activity2" >
<intent-filter>
<action android:name="fdsfds.hihi" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Why my intent cannot launch .MainActivity2 ?
Upvotes: 1
Views: 2099
Reputation: 11
This is probably too late for you to get your answer. I landed here because I had exactly the same doubt as you. I think you have made the same mistak as I did. I confused the intent object with intent filter. But on a careful reading of the documentation my doubt was resolved.
So, if the intent-object (the intent objected that you created) doesn't specify any action but your intent-filter (in the manifest file) has at least one action listed, your intent will pass the action test. There is no gurantee though that it'll pass the rest of the tests for intent matching.
You haven't listed any action in the filter and hence all the action tests would fail (and by extention the intent matching will fail).
Upvotes: 1
Reputation: 8030
Even though one year is passed I'll answer.
First, I agree with you, sometimes the Android doc is inconsistent, it leaves some doubts.
However in this case the documentation is right:
if an Intent does not specify an action, it will pass the test (as long as the filter contains at least one action).
What the documentation doesn't say is that if the action isn't defined then at least the data field (or mime field) must be defined.
In conclusion there can not be an intent without neither an action or a data.
As @Amrut Bidri said, you can't ride a bike without fuel.
Upvotes: 0
Reputation: 6360
Intent intent = new Intent();
intent.setAction("fdsfds.hihi");
startActivity(intent);
Upvotes: 0