有没有一种有效的方法从 Bundle 转换为 ContentValues?

发布于 2025-01-06 07:33:13 字数 115 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

煞人兵器 2025-01-13 07:33:13

我扫描了 Android 源代码,两个类都使用 Map 来保存底层数据。具体来说,Bundle 使用 Map,ContentValues 使用 HashMap

但是,Bundle 允许加载任何可分包对象,而 ContentValues 的实现则接受基本类型类(Integer、String、Double 等)和字节数组。

因此,原则上, ContentValuesBundle 的特殊情况,因此从 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 a Map and ContentValues uses a HashMap.

However, Bundle permits any parcelable objects to be loaded, while ContentValues' implementation accepts the primitive type classes (Integer, String, Double etc.) and byte arrays.

So it looks like in principle, ContentValues is a special case of Bundle, so converting from ContentValues to Bundle might have been possible if the internals were accessible, but the reverse is problematic, since a Bundle can hold objects not strictly compatible with ContentValues.

Any comments on this are welcome.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文