Search code examples
androidserializableparcelable

what is difference between Parcelable and Serialization used in android


I want to know exact ,

  1. whether should I used parcelable or serialization technique for sending data from one activity to other?
  2. is it compulsory to use one of them for sending data from one to other?
  3. when should I use them?
  4. and the exact difference between them and performance of both of them in java aspects.

Thanks in advance.


 public class GetSetClass implements Serializable {
    private int dt = 10;

    /** pass any object, drwabale */
    public int getDt() {
        return dt;
    }

    public void setDt(int dt) {
        this.dt = dt;
    }
}

Solution

  • whether should i used parcelable or serialization technique for sending data from one activity to other.

    If you are sending a non-primitive type data/Object to another activity through the intent you have to either Serialize or implement Parcelable for that object. The preferred technique is Parcelable since it doesn't impact the performance.

    is it compulsory to use one of them for sending data from one to other. / when should i use them.

    It is only compulsory/used for sending non-primitive type data objects.

    and the exact difference between them and performance of both of them in java aspects.

    Serialization does impact the performance. For more details check this link Android Parcelable and Serializable