Android Intent passing parcelable object vs passing Json string

EDIT: If you hate writing 'Parcelable' boilerplate code like me, you could use the Parcelable code generator plugin with your Android Studio/IntelliJ IDE. It will auto generate the methods for marshalling and unmarshalling your class fields. Very easy to use and highly recommended.


As much as I hate answering my own questions, I thought of sharing my observations that could help other developers in future.

Transmission of data from one activity to another can be done using either passing Serializable or Parcelable Objects in an activity intent. Android developer website recommends using Parcelable interface for this purpose.

However, my question was pertaining to the efficiency comparison between passing Parcelable object and JSON string.

To test this, I used an old and low-end Android device. I launched an activity by sending a large Parcelable Object in an activity intent. Next, I launched the same activity using the JSON String of the same object in the activity intent. What I observed was a significant observable latency while launching an activity by sending a JSON String instead of Parcelable Object.

In conclusion, even if we pass a JSON String, Java String object always implements Serializable. Google recommends using Parcelable instead of Serializable objects. This will usually be insignificant in case of strings of negligible length. However, in the case of massive Json Strings of massive objects, The efficiency will certainly take a toll.

You could refer this for performance benchmark of Parcelable vs Serializable.


TLDR:

  • Parcelable - More boilerplate code, better performance and a better engineering practice overall.

  • Serializable - Less code, easy to learn and acceptable if you're not obsessed with performance/best practices.