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传入进去的。

  • 相关阅读:
    Linux数据备份
    eclipse 中使用等宽字体 inconsolata
    在ubuntu14.04 64位中使用jd-gui
    Fragment 常见问题
    ClassNotFoundException
    符号表的简单使用
    一个简单的词法分析器
    一个简单的语法分析器(后缀式转换)
    火狐无法显示图片
    ftp 匿名访问设置
  • 原文地址:https://www.cnblogs.com/llguanli/p/6855986.html
Copyright © 2011-2022 走看看