We were wondering if when using Bundle
with serializable or parcelable objects, when does the marshalling actually happen? As soon as you put it in the bundle? Since bundles are mostly used to simply pass around data between two screens (we're not even talking about IPC here!), there doesn't seem to be much point in marshalling an object, since it stays in memory all the time, no?
Are we right in assuming that marshalling (be it Java serializing or Android parcelling) only happens if
I've seen Android framework engineers (I believe it was Dianne Hackborn) say that one should use Parcelable
instead of Serializable
because the former is much faster. How much faster? And will this even make a difference if the object isn't marshalled most of the time anyway (assuming our assumptions about this were right)?
I think I've figured it out. I basically spent the entire last day and most of today on debugging through the Android Parcel
and Bundle
source code, and here is how it works:
HashMap
, but it supports to parcel (i.e. marshal) that internal map and its contentsSo generally: NO, a value is not parceled simply by putting it into a Bundle. Instead, parcelling happens when passing the Bundle to another component (activity or service; why Android does that, I don't know, since no IPC is happening technically.) or when it otherwise has to be parcelled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With