Bundle类解析

Bundle类源码浅读

从String键到各种Parcelable值的映射。

使用场景:

  • activity中用于保存activity的状态信息
  • 使用Intent传递封装到Bundle中的数据

一、数据的存取方法:

1.简单类型的数据存入putXXX():

  • putByte(@Nullable String key, byte value)
  • putChar(@Nullable String key, char value)
  • putShort(@Nullable String key, short value)
  • putFloat(@Nullable String key, float value)
  • putCharSequence(@Nullable String key, @Nullable CharSequence value)
  • putParcelable(@Nullable String key, @Nullable Parcelable value)
  • putSerializable(@Nullable String key, @Nullable Serializable value)
向Bundle中放入一个可序列化的对象
  • putBundle(@Nullable String key, @Nullable Bundle value)
向Bundle中放入一个Bundle对象

2.Array数组的存入方法putXXXArray()

  • putByteArray(@Nullable String key, @Nullable byte[] value)
  • putShortArray(@Nullable String key, @Nullable short[] value)
  • putCharArray(@Nullable String key, @Nullable char[] value)
  • putFloatArray(@Nullable String key, @Nullable float[] value)
  • putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value)
  • putParcelableArray(@Nullable String key, @Nullable Parcelable[] value)
  • putSparseParcelableArray(@Nullable String key, @Nullable SparseArray

3.ArrayList存入的方法putXXXArrayList()

  • putIntegerArrayList(@Nullable String key, @Nullable ArrayList value)
  • putStringArrayList(@Nullable String key, @Nullable ArrayList value)
  • putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList value)
  • putParcelableArrayList(@Nullable String key, @Nullable ArrayList

二、Bundle类中对bundle对象操作的方法

/**
 * Clones the current Bundle. The internal map is cloned, but the keys and
 * values to which it refers are copied by reference.
 */
@Override
public Object clone()

/**
 * Removes all elements from the mapping of this Bundle.
 */
@Override
public void clear()

/**
 * Removes any entry with the given key from the mapping of this Bundle.
 *
 * @param key a String key
 */
public void remove(String key)

/**
 * Inserts all mappings from the given Bundle into this Bundle.
 *
 * @param bundle a Bundle
 */
public void putAll(Bundle bundle)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值