【问题标题】:Passing objects between activities in android why Parcelable ? why not JSON string?在 android 中的活动之间传递对象为什么 Parcelable ?为什么不是 JSON 字符串?
【发布时间】:2015-04-14 22:43:16
【问题描述】:

我想知道为什么活动之间的对象交换以 Parcelable 形式进行,为什么不以 JSON 字符串形式进行。我了解 Parcelable 比序列化更好。任何人都可以在 Parcelable 和 JSON 之间进行比较。

【问题讨论】:

  • 关于 Android 中的 Parcelable 和序列化的好文章:url

标签: android json parcelable


【解决方案1】:

我想知道为什么活动之间的对象交换是 Parcelable 的,为什么不是 JSON 字符串

并非所有可以进入a Parcel 的内容都可以进入 JSON 字符串,例如:

  • IBinder 对象(与使用 AIDL 的远程服务相关联)
  • ParcelFileDescriptor
  • Exception

此外,虽然您可以将 byte[] 转换为 String(例如,base-64 编码),但效率会很低。

【讨论】:

    【解决方案2】:

    Parcelable 级别非常低。因此,它比现在在 android 上可用的所有其他东西(如 Serializeable)要快得多。 Json 在性能(写入和读取 json 时考虑性能问题)和内存空间方面没有任何意义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-03
      • 2011-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-08
      相关资源
      最近更新 更多