0

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 ?

3 Answers3

1

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).

0
Intent intent = new Intent();
intent.setAction("fdsfds.hihi");
startActivity(intent);
Amrut Bidri
  • 6,276
  • 6
  • 38
  • 80
  • Thats not what I want to do. I would like to test whether an intent object without action can pass the intent filter or not just like said in android document. – user2894168 Dec 02 '14 at 13:50
  • this means you want to ride a bike without petrol in it. the intent will not call any activity until you provide minimum data required in that intent. – Amrut Bidri Dec 02 '14 at 13:51
  • Yup. So you think it is a mistake in android document? – user2894168 Dec 02 '14 at 13:53
  • post that link here or document that u say. i want to take a look at it. – Amrut Bidri Dec 02 '14 at 13:53
  • if an Intent does not specify an action, it will pass the test (as long as the filter contains at least one action). (from this document) – user2894168 Dec 02 '14 at 14:02
  • you are reading it below **Intent Resolution** so stay aware of it. Let me know what is your purpose for doing so and remember as i told intent needs petrol to ride itself. – Amrut Bidri Dec 02 '14 at 14:10
  • My purpose is just for academic study. Why do I need to stay aware of it? It clearly stated that an intent without action can pass any intent filter. – user2894168 Dec 02 '14 at 14:44
0

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.

zer0uno
  • 7,521
  • 13
  • 57
  • 86