what is difference between Parcelable and Serialization used in android

后端 未结 5 889
北恋
北恋 2020-12-14 06:33

I want to know exact ,

  1. whether should I used parcelable or serialization technique for sending data from one activity to other?
5条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 06:52

    Got a very good explanation of difference between Parcelable and Serialization.

    To start with your question though its been a long time, it may help others:

    1. whether should I used parcelable or serialization technique for sending data from one activity to other?

    Ans: Parcelable is best choice (why explained later).

    1. is it compulsory to use one of them for sending data from one to other?

    Ans: Yes, as sending data (object) from one to other requires streams of bytes to be written and retrieved and that can be done either through parcelable or serialization.

    1. when should I use them?

    Ans: This part you arleady answered i.e, passing data from one activity to another.

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

    Ans: 1. Parcelable is well documented in the Android SDK; serialization on the other hand is available in Java.

    1. In Parcelable, developers write custom code for marshaling and unmarshaling so it creates less garbage objects in comparison to Serialization. The performance of Parcelable over Serialization dramatically improves (around two times faster), because of this custom implementation.

    2. Serialization is a marker interface, which implies the user cannot marshal the data according to their requirements. In Serialization, a marshaling operation is performed on a Java Virtual Machine (JVM) using the Java reflection API. This helps identify the Java objects member and behavior, but also ends up creating a lot of garbage objects. Due to this, the Serialization process is slow in comparison to Parcelable.

    Answer taken from: this link

    See also:serialization explained

提交回复
热议问题