Android Development — Serializable vs Parcelable

Sarah Maher
2 min readNov 9, 2021

The Need ..

Passing data between different destinations in our Android applications is something that we have to do very often. Passing primitives like Integer and String is a piece of cake, but what if I wanted to pass an object of a class that Ive created?

Our Object is going on a trip!

The packing..

In order to transfer the object we need to pack our object, this is achieved through marshalling; which refers to the process of converting the data or the objects into a byte-stream.

The unpacking..

After we receive the needed object in a form of byte-stream through marshalling we need to start the unmarshalling; which is the process of converting the byte-stream back to their original object.

The Means…

Serializable

Serializable is a standard Java interface, when using Serialization the marshalling operation is performed on a JVM using Reflection, This is why its usually described as the slower approach when in comparison with parcelable.

Serializable have a major advantage that it is easier to implement, here take a look!

Parcelable

Parcelable requires the developer to write some custom code for marshalling and unmarshalling, due to this custom code Parcelable performance is described faster than our fellow Serializable.

The Amount of code that should be provided is indeed more than the case of Serializable. here is an example:

Plugin to the rescue!

Using Parcelable don’t have to compromise the development time, there is a plugin that can help you by generating the boilerplate code needed.

Check it out here: https://plugins.gradle.org/plugin/org.jetbrains.kotlin.plugin.parcelize

Final Verdict

Parcelable is faster that Serializable with more code to write, while Serializable is easier to write but slightly slower.

This is all the info you need to choose and the decision is up to you.

Resources

What do mean by marshalling?

--

--

Sarah Maher

An Engineer Who Keeps talking about Android || Women In Tech || Find me on LinkedIn : https://www.linkedin.com/in/sarah-maher-awad/