zoukankan      html  css  js  c++  java
  • android开发之Bundle使用

    android开发中,我们经常需要在两个activity之间传递数据,最常用的莫过于使用intent.putXXX(),可是很多时候我们也会这样:

    Bundle bundle = new Bundle();
    bundle.putXXX()...

    这两种传值方式很像,今天查看intent.putXXX()方法源代码,发现是这样的:

        /**
         * Add extended data to the intent.  The name must include a package
         * prefix, for example the app com.android.contacts would use names
         * like "com.android.contacts.ShowAll".
         *
         * @param name The name of the extra data, with package prefix.
         * @param value The boolean array data value.
         *
         * @return Returns the same Intent object, for chaining multiple calls
         * into a single statement.
         *
         * @see #putExtras
         * @see #removeExtra
         * @see #getBooleanArrayExtra(String)
         */
        public Intent putExtra(String name, boolean[] value) {
            if (mExtras == null) {
                mExtras = new Bundle();
            }
            mExtras.putBooleanArray(name, value);
            return this;
        }

    是的,你没看错,intent.putXXX()方法其实也是先new一个bundle出来,然后利用bundle来传值。由此可以看到intent中关于传值的接口bundle中都有,但是bundle中有的intent中不一定有,也就是说bundle的传值功能更为强大。

  • 相关阅读:
    内部排序一
    安全的文件访问方式
    Json序列化
    对进度条的通用封装实现
    关于'//'解答
    jquery中美元符号($)命名冲突
    linux 文件属性与权限
    【层次查询】Hierarchical Queries之亲兄弟间的排序(ORDER SIBLINGS BY)
    How to create a freehand tool
    C# 获取COM对象 ProgId ClsId
  • 原文地址:https://www.cnblogs.com/qitian1/p/6461771.html
Copyright © 2011-2022 走看看