相信大家都看过官方文档中如下的一段(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>

</set>

原文地址: http://weibo.com/p/1001603911234926855853?from=page_100505_profile&wvr=6&mod=wenzhangmod

关于intent-filter的误区相关推荐

  1. 3.1 Android组件intent filter

    3.1.0 Intent filter基本概念 前面章节我们说到了Intent,Intent对象中除了ComponentName可以直接指定目标组件外,其它的属性都无法直接指定目标组件.当然我们这里不 ...

  2. intent Filter

    intent Filter 一.介绍 如果一个 Intent 请求在一片数据上执行一个动作, Android 如何知道哪个应用程序(和组件)能用来响应这个请求呢? Intent Filter就是 用来 ...

  3. Android Intent And Intent Filter

    2019独角兽企业重金招聘Python工程师标准>>> 1.概述 一个应用程序的三个核心组件--activities.services.broadcast receivers,都是通 ...

  4. Android 意图(Intent)和过滤器(Filter)

    Android意图是一个要执行的操作的抽象描述.它可以通过 startActivity 来启动一个活动,broadcastIntent 来发送广播到任何对它感兴趣的广播接受器组件,startServi ...

  5. android之android.intent.category.DEFAULT的用途和使用

    1.要弄清楚这个问题,首先需要弄明白什么是implicit(隐藏) intent什么是explicit(明确) intent. Explicit Intent明确的指定了要启动的Acitivity , ...

  6. 描述一下 Intent 和 IntentFilter?

    Android 中通过 Intent 对象来表示一条消息,一个 Intent 对象不仅包含有这个消息的目的地,还可以包含消 息的内容,这好比一封 Email,其中不仅应该包含收件地址,还可以包含具体的 ...

  7. Android -- Intent

    Intent                                                                                       Android ...

  8. 【Android基础】趣谈Intent

    Intent Intent 顾名思义,意图 类比一下,假如说把android系统中的每个Activity都看成是一个个的人,我们每个人绝不是超人,即会去响应别人的请求,也会要求得到别人的帮助,这样才能 ...

  9. Intent Android 详解

    Intents and Intent Filters 三种应用程序基本组件 activity, service和broadcast receiver--是使用称为intent的消息来激活的. Inte ...

  10. Android -- 再来一发Intent

    之前写过一篇Intent的博客,主要说了一下隐式意图. 传送门:<Android -- Intent> Intent对象构成 Component name.Action.Data.Cate ...

最新文章

  1. 漫画讲解HDFS原理
  2. android顶部导航高度,Android特效——————底部/顶部导航条(Fragment+ViewPaper+XTabLayout)...
  3. Hive的使用之hwi
  4. win10录屏工具_win10录屏软件选哪款?没用过别后悔
  5. 修改 Docker 的镜像存储位置
  6. 微软删除最大的公开人脸识别数据集,只因员工离职?!
  7. MeterSphere场景变量—常量整理总结
  8. iview在项目中遇到的坑
  9. linux重定向文件容加时间,linux – Shell重定向和文件I / O持续时间
  10. php小偷程序生成,php开发:php小偷程序实例代码
  11. 【Java爬虫】接口模拟微信公众号登录,搜索公众号,获取公众号文章,java实现
  12. ucinet网络分析使用总结
  13. STC15单片机-无线通讯(WIFI模块)
  14. DataWhale_Pandas Task08 文本数据
  15. 101平衡模式 DIR的理解
  16. MAC去掉更新小红点
  17. ipmitool 命令行重启服务器
  18. 【青龙面板】天翼云盘签到
  19. Ride测试用例报 Suite xxxx contains no tests matching name
  20. php通用查询系统excel,Laravel+Excel通用查询填报系统

热门文章

  1. soso街景开发——在移动应用(网站)中的应用
  2. 问题小结(6)-listview滚动条相关
  3. HttpMoudle实现用户身份验证
  4. 吴恩达deeplearning资源汇总帖
  5. CentOS启用sudo方法
  6. 游戏人物标记——腾讯笔试
  7. [云炬创业管理笔记]第九章为创业成败而准备测试5
  8. [ 云炬创业基础笔记]商业模式创新
  9. 科大星云诗社动态20220102
  10. wdcp后台重启服务器后mysql打不开