Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default when using multiple Actions in Intent-Filter

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?

like image 334
Adam Haile Avatar asked Jul 06 '10 17:07

Adam Haile


People also ask

Can an activity have multiple Intent filters?

If it fails to match even one of them, the Android system won't deliver the intent to the component. However, because a component may have multiple intent filters, an intent that does not pass through one of a component's filters might make it through on another filter.

What is Intent category default?

The category DEFAULT is automatically applied to all implicit intents (by default) so because of the reason above every Activity that want to receive any implicit intent at all has to include this category in its Intent-filter.

What is Intent filter priority?

An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.

What is difference between Intent and Intent filter in android?

An intent is an object that can hold the os or other app activity and its data in uri form.It is started using startActivity(intent-obj).. \n whereas IntentFilter can fetch activity information on os or other app activities.


1 Answers

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.

like image 198
CommonsWare Avatar answered Oct 23 '22 07:10

CommonsWare