zoukankan      html  css  js  c++  java
  • Android------Intent.createChooser

           Intent的匹配过程中有三个步骤,包含Action categorydata 的匹配。

    假设匹配出了多个结果。系统会显示一个dialog让用户来选    择。例如以下图:

         那么今天我们主要是解说一下,怎样自己定义这个Chooser的标题?

         代码事实上非常easy,例如以下:

    1. Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    2. intent.setType("audio/*");
    3. startActivity(Intent.createChooser(intent, "Select music"));

         可能非常多同学就会疑问究竟在createChooser()方法里面,android做了什么?

         我们再来看看这种方法的源代码:

    1. public static Intent createChooser(Intent target, CharSequence title) {
    2. Intent intent = new Intent(ACTION_CHOOSER);
    3. intent.putExtra(EXTRA_INTENT, target);
    4. if (title != null) {
    5. intent.putExtra(EXTRA_TITLE, title);
    6. }
    7. return intent;
    8. }

         这下大家应该清楚了,原来在调用createChooser()方法时候,系统又创建了一个新的Action为ACTION_CHOOSER的Intent ,并把我们的原始Intent当成了參数传进去 。选择器的title是通过 EXTRA_TITLE传入进去的。

  • 相关阅读:
    springBoot启动异常 Failed to load ApplicationContext
    mysql存储过程
    springBoot集成Swagger
    groupmems命令:更改和查看组成员 和 usermod命令修改组
    javaBean简介
    Angular获取dom元素,以及父子组建之间相互传值
    Lambda表达式
    坐标转换
    扩展方法
    Binding的Path(路径)
  • 原文地址:https://www.cnblogs.com/llguanli/p/6855986.html
Copyright © 2011-2022 走看看