Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

serializable - 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;
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

These concepts are related to Inter Process Communication (IPC).

When sending data between two applications, we have to make sure that both applications should understand the format of the data that is being sent.

Especially when you are sending non primitive data type values like classes and objects between two applications, We have to convert them into Operating System understandable format. O.S understands only primitive types (ints, chars etc). The reason for conversion is we have to O.S communication channel to transmit the data.

This process of converting Non primitive types to primitives and sending across to other application over some communication channel is called as Serialization. The reverse process is called as De Serialization.

In Java, IPC depends heavily on Serializables for serialization. But serialization is designed by keep desktop applications in mind. When you are doing IPC in mobile applications we have to make sure that the process of IPC is not too heavy.

In simple terms serialization is a heavy concept for IPC. So in place of Serialization Android opted for Binders for achieving light weight Inter process communication. Binders internally depends heavily on parcels, to do the IPC. Parcels are light weight serializables. It is preferred to use parcels for marshaling objects into byte streams.

Note: Binder IPC heavily depends on Shared memory concept to make sure that there is not much data duplication while sharing between applications.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...