android - intent filter without action -
android's documentation says:
http://developer.android.com/reference/android/content/intentfilter.html
"action matches if of given values match intent action, or if no actions specified in filter."
i tried test it. in test application set such filter 1 of activities:
<intent-filter> <action android:name="ma" /> <category android:name="android.intent.category.default" /> <category android:name="mk1" /> </intent-filter>
i try send such intent:
intent = new intent(); i.setaction("ma"); i.addcategory("mk1"); startactivity(i);
it works - activity gets started.
then comment out action in filter:
<intent-filter> <!-- <action android:name="ma" /> --> <category android:name="android.intent.category.default" /> <category android:name="mk1" /> </intent-filter>
again send same intent. activity doesn't start.
why? according documentation, when filter has no actions specified, intent actions should fullfill it.
refer documentation on intentfilters following description of action test in section on intent resolution:
as example shows, while intent object names single action, filter may list more one. list cannot empty; filter must contain @ least 1 element, or block intents.
to pass test, action specified in intent object must match 1 of actions listed in filter. if object or filter not specify action, results follows:
if filter fails list actions, there nothing intent match, intents fail test. no intents can through filter.
on other hand, intent object doesn't specify action automatically passes test — long filter contains @ least 1 action.
it pretty clear intentfilter
contains no actions not match any intent
objects. seeing.
on other hand, absolutely agree documentation inconsistent. section copied here inconsistent, states both "a filter must contain @ least 1 element, or block intents" , "an intent object doesn't specify action automatically passes test — long filter contains @ least 1 action."
Comments
Post a Comment