Is a serializable object always serialized when inserted into a package?

We were wondering if, when using the Bundle with serializable or legible objects, when does sorting actually happen? Once you put it in a bunch? Since bundles are mainly used to simply transfer data between two screens (we are not even talking about IPC here!), It seems that there isn’t much point in sorting an object since it remains in memory all the time, no

Do we assume that marshalling (whether it is Java serialization or Android parking) occurs only if

  • data must be transferred to another process, for example. during RMI or
  • component (activity or service) is destroyed, and the state of the instance should be written to disk?

I saw the developers of the Android framework (I believe it was Dianne Hackborn) say that instead of Serializable , you should use Parcelable , because the first is much faster. How much faster? And will it even matter if the object is not sorted in most cases in any case (assuming that our assumptions about this were correct)?

+6
android serializable marshalling bundle parcelable
source share
2 answers

I think I get it. I basically spent the last day and most of today debugging through the Android Parcel and Bundle source code, and here's how it works:

  • The package is basically a wrapper around the HashMap , but it supports the parcel (i.e. marshal) that the internal map and its contents
  • if you put the value in the Bundle, it will first disable this internal map, and then just put the value in this map.
  • Correction of the map is lazy: it will parallelize it if you try to access it (for example, by calling bundle.putParcelable ()). Even then, he will only separate the card itself, but not its values. Only when you try to actually access these values ​​(for example, using bundle.getParcelable ("key")) will it also separate the value. In other words, if you are sending something inside the Bundle, unparcelling will not happen, if you never get access to these values ​​again.

So, as a rule: NO , the value is not divided simply by putting it in the Bundle. Instead, packet transfer occurs when the Bundle is transferred to another component (activity or service, why Android does this, I do not know, since IPC does not happen technically). Or when it otherwise needs to be shared.

+6
source share

I think this happens right away. And I think that the increase in productivity is due to the serializable necessary reflection for the job. I think this is the same as the performance difference between serializable and external.

0
source share

All Articles