有没有一种有效的方法从 Bundle 转换为 ContentValues?
Bundle 和 ContentValues 类似乎具有非常相似的功能。
是否有一种有效的方法可以从一个元素转换为另一个元素(反之亦然),而无需循环遍历类,随后在每个元素上调用 get 和 put ?
The Bundle and ContentValues classes seem to have pretty similar functionality.
Is there an efficient way of converting from one to another (and vice-versa) without having to loop through the classes, calling get and put subsequently on each element?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我扫描了 Android 源代码,两个类都使用
Map
来保存底层数据。具体来说,Bundle
使用Map
,ContentValues 使用HashMap
。但是,
Bundle
允许加载任何可分包对象,而ContentValues
的实现则接受基本类型类(Integer、String、Double
等)和字节数组。因此,原则上,
ContentValues
是Bundle
的特殊情况,因此从ContentValues
转换为Bundle
可能如果内部可访问,则这是可能的,但反之则有问题,因为Bundle
可以容纳与ContentValues
不严格兼容的对象。欢迎对此提出任何意见。
I've scanned the Android source code and both Classes use a
Map
to hold the underlying data. Specifically,Bundle
uses aMap
and ContentValues uses aHashMap
.However,
Bundle
permits any parcelable objects to be loaded, whileContentValues
' implementation accepts the primitive type classes (Integer, String, Double
etc.) and byte arrays.So it looks like in principle,
ContentValues
is a special case ofBundle
, so converting fromContentValues
toBundle
might have been possible if the internals were accessible, but the reverse is problematic, since aBundle
can hold objects not strictly compatible withContentValues
.Any comments on this are welcome.