Ivan Skoric

Android developer.


Serializable vs Parcelable in Android

When trying to pass the data between the different components in Android, we would often need to pass the whole objects. There are two options to do that, we could either implement standard Java interface called Serializable, or Parcelable – specifically designed for Android.

The latter is recommended in Android applications, because it turns object’s data fields into primitive data types first, so that performance is increased significantly – which is considerably noticeable when passing a lot of objects.

Serializable

Implementing Serializable is a lot easier than Parcelable, we just need to implement it in the class that we want to pass as data. Also, we have to implement it in nested classes, if any. No additional code.

import java.io.Serializable;
import java.util.List;

public class CustomClass implements Serializable {
    int a, b;
    String s;
    List list;

    static
...

Continue reading →