Why serialize object to send in another Activity?

11

What is the explanation for serializing the object either using the serializable or Parcelable implementation. I know this serves to create a new instance of the object in the other activity, but why "can not" use the same instance of it in the other activity?

    
asked by anonymous 20.08.2015 / 00:35

1 answer

6

According to this question in OS you need to serialize objects because they are passed to a class called ActivityManagerNative which is in a separate process from the other applications.

When two distinct processes want to communicate memory is not shared and therefore it is not possible to move the same object from one to another.

But the answer does not go into the merit of why communication was designed to work that way.

The most likely explanation is that Android's% com_communication communication engine is designed to work both between components ( Intent , Activities , etc.) of the same process (application) and between components of different processes (from% application_com% A to% application_com% B, for example).

That is, serialization is required to allow data transfer via Services (Interprocess communication).

Between two Activity of the same process it is possible to communicate without serializing the object, just do not use the Activity mechanism and instead use a shared resource (a static global object or inherited by both IPC , or even a Singleton ).

    
20.08.2015 / 04:09