Why serialize object to send in another Activity?

Asked

Viewed 336 times

11

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

  • 2

    Related: http://answall.com/q/38492/4808

1 answer

6


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

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

But the answer does not enter into the merit of why the communication was designed to work like this.

The most likely explanation is that the mechanism of communication by Intent's Android was designed to work both between components (Activities, Services, etc.) of the same process (application) as between components of different processes (of a Activity from application A to Activity application B, for example).

That is, serialization is necessary to allow data transfer via IPC (Inter-process communication).

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.