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的传值功能更为强大。

  • 相关阅读:
    redis 基础知识
    vue + django 项目部署
    django 的静态资源
    uwsgi 与 supervisor
    django基础之orm(models)初识
    django基础之模板Template
    django基础知识之视图views
    django基础知识之django介绍及url
    django基础之Web框架介绍
    mysql之pymysql模块相关
  • 原文地址:https://www.cnblogs.com/qitian1/p/6461771.html
Copyright © 2011-2022 走看看