0 votes
in Android by
What is the difference between Serializable and Parcelable? Which is the best approach in Android?

1 Answer

0 votes
by

While developing applications usually it needs to transfer data from one activity to another. This data needs to be added into a corresponding intent object. Some additional actions are required to make the data suitable for transfer. For doing that the object should be either serializable or parcelable.

Serializable:

Serializable is a standard Java interface. In this approach, you simply mark a class Serializable by implementing the interface and java will automatically serialize it.

Reflection is used during the process and many additional objects are created. This leads to plenty of garbage collection and poor performance.

Parcelable:

Parcelable is an Android-specific interface. In this approach, you implement the serialization yourself.

Reflection is not used during this process and hence no garbage is created.

Parcelable is far more efficient than Serializable since it gets around some problems with the default Java serialization scheme. Also, it is faster because it is optimized for usage on the development of Android, and shows better results.

...