Default when using multiple Actions in Intent-Filter

▼魔方 西西 提交于 2020-01-03 16:59:23

问题


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:


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.



来源:https://stackoverflow.com/questions/3188867/default-when-using-multiple-actions-in-intent-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!