tags:

views:

60

answers:

1

Trying to grok intents and actions in android and looking through the documentation. But one thing I keep seeing is an intent filter with multiple actions defined. Like this, from the above link:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.intent.action.EDIT" />
    <action android:name="android.intent.action.PICK" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
</intent-filter>

But, if you call that activity, how does it choose which action is chosen?

For that matter, that linked to example has multiple activities that all contain the same actions, "android.intent.action.VIEW" for example. When calling this with something like content://com.google.provider.NotePad/notes how does it even know which activity to use?

+1  A: 

But, if you call that activity, how does it choose which action is chosen?

The Intent has an action. If that action matches one of the three in the Intent filter, and matches on the category, and matches on the MIME type, then it will match the Intent filter overall and will start the activity.

In other words, multiple actions (or any other element) are a logical OR.

For that matter, that linked to example has multiple activities that all contain the same actions, "android.intent.action.VIEW" for example.

And generally there is stuff in the Intent filters to distinguish one from the next.

When calling this with something like content://com.google.provider.NotePad/notes how does it even know which activity to use?

It asks the content provider, "yo, dawg -- what's the MIME type for this, yo?". Given the MIME type from the content provider, it can find any matching Intent filters.

CommonsWare
In the linked example all of the MIME types are exactly the same. So how can it tell?
Adam Haile
What do you want to tell? What do you want to do exactly and doesn't work?
Pentium10
+1 Liked `"yo, dawg -- what's the MIME type for this, yo?"`
Pentium10
@Adam Haile: "In the linked example all of the MIME types are exactly the same." No, they're not. "dir" != "item" in the MIME types. Each of those intent filters either differs on actions or MIME type from any other filters in the manifest. @Pentium10: Android is "street", fo shizzle. :-)
CommonsWare