首页 > 移动平台 > 详细

android开发之Bundle使用

时间:2015-07-30 14:57:22      阅读:131      评论:0      收藏:0      [点我收藏+]

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

版权声明:本文为博主原创文章,未经博主允许不得转载。若有错误地方,还望批评指正,不胜感激。

android开发之Bundle使用

原文:http://blog.csdn.net/u012702547/article/details/47148805

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!