相信大家都看过官方文档中如下的一段(http://developer.android.com/guide/components/intents-filters.html):
Action test
To specify accepted intent actions, an intent filter can declare zero or more <action> elements. For example:
<intent-filter><action android:name = "android.intent.action.EDIT" />
<action android:name = "android.intent.action.VIEW" />
...
</intent-filter>
To get through this filter, the action specified in the Intent must match one of the actions listed in the filter.
If the filter does not list any actions, there is nothing for an intent to match, so all intents fail the test. However, if an Intent does not specify an action, it will pass the test (as long as the filter contains at least one action).
关于这一段描述,读起来好像是含糊不清甚至自相矛盾的,而国内一些翻译后的文章也就直接翻译了,结果就是翻译者和读者理解起来都含糊不清。而stackoverflow上也有人对此提出了质疑,如下所示:
事实情况如何呢?的确是官方文档描述的不严谨,以至于看起来前后矛盾了(inconsistent)。
这里对官方文档中的描述做下补充。
首先,这一句话:“
To get through this filter, the action specified in the
Intent
must match one of the actions listed in the filter.
If the filter does not list any actions, there is nothing for an intent to match, so all intents fail the test.
”是完全正确的,但是这个“
However, if an
Intent
does not specify an action, it will pass the test (as long as the filter contains at least one action)”是有争议的,并且看起来和However之前的描述自相矛盾,分三点来说明这个However:
1. 如果action只和category组合使用(隐式调用的条件),那么这个
However是不对的,intent中不指定action,那么无法启动目标组件(一般为Activity);
2. 如果action和category、data组合使用,那么这个However是对的,如下代码可以启动目标组件,尽管intent中没有指定action:
3. 我们可以看出,在intent-filter中的action、category和data中,action是主要的,而category和data算是辅助的,但是上面的一个However制造出了一个特殊的场景,那就是“intent-filter中列出了action,但是intent中没有指定action,然而却匹配成功了”,这看起来又和“
To get through this filter, the action specified in the
Intent
must match one of the actions listed in the filter.”这句话矛盾了。
结语:官方文档仍然需要抱着怀疑的态度去看。向如下错误,我就不提了,硬把restart写成repeat。
SYNTAX:
<
set
android:ordering = ["together" | "sequentially" ] >
< objectAnimator
android:propertyName = " string "
android:duration = " int "
android:valueFrom = " float | int | color "
android:valueTo = " float | int | color "
android:startOffset = " int "
android:repeatCount = " int "
android:repeatMode = [" repeat " | "reverse" ]
android:valueType = ["intType" | "floatType" ] />
< animator
android:duration = " int "
android:valueFrom = " float | int | color "
android:valueTo = " float | int | color "
android:startOffset = " int "
android:repeatCount = " int "
android:repeatMode = ["repeat" | "reverse" ]
android:valueType = ["intType" | "floatType" ] />
< set >
...
</set>
android:ordering = ["together" | "sequentially" ] >
< objectAnimator
android:propertyName = " string "
android:duration = " int "
android:valueFrom = " float | int | color "
android:valueTo = " float | int | color "
android:startOffset = " int "
android:repeatCount = " int "
android:repeatMode = [" repeat " | "reverse" ]
android:valueType = ["intType" | "floatType" ] />
< animator
android:duration = " int "
android:valueFrom = " float | int | color "
android:valueTo = " float | int | color "
android:startOffset = " int "
android:repeatCount = " int "
android:repeatMode = ["repeat" | "reverse" ]
android:valueType = ["intType" | "floatType" ] />
< set >
...
</set>
</set>
原文地址: http://weibo.com/p/1001603911234926855853?from=page_100505_profile&wvr=6&mod=wenzhangmod