为什么在 android 中的活动之间传递对象 Parcelable?为什么不是 JSON 字符串?

Passing objects between activities in android why Parcelable ? why not JSON string?

我想知道为什么活动之间的对象交换是作为 Parcelable 而不是 JSON 字符串。我理解 Parcelable 比序列化更好。任何人都可以比较 Parcelable 和 JSON.

I would like to know why object exchange between activities is made as Parcelable and why not as a JSON string

并非所有可以放在 a Parcel 中的都可以放在 JSON 字符串中,例如:

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

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

Parcelable 级别很低。因此,它比现在 android 上可用的所有其他东西(如 Serializeable)快得多。 Json 对于性能(在写入和读取时考虑性能问题 json)和内存 space.

没有任何意义