When you put a serializable into a bundle, the bundle holds on to the object reference UNTIL it needs to be marshalled across processes. At that point it will get serialized into a byte stream, the bundle will be written into a parcel, and the other side will receive a new bundle object with a different serializable object.
Pretty much everywhere Bundle is used in the system, it will go through an IPC at some point, so you need to assume the objects in it will get serialized. About the only exception to that is the Bundle in Message, since Message normally doesn't go across processes unless sent through a Messenger. But if you are using the normal local Message sending facility, there is really no reason to use the Bundle there, since you can just stick whatever you want (including a HashMap of multiple items or your own custom cloass) in the 'obj' field. Also I strongly recommend staying away from serialization. It is super super slow compared to Parcelable. On Tue, Mar 24, 2009 at 3:20 AM, Matthias <m.kaepp...@googlemail.com> wrote: > > Hi, > > I was wondering about the behavior of Bundles and serializable > objects. If I put a serializable object into a bundle, what is > serialized then, the reference to the object or the object itself? > > I always assumed that the object itself would be serialized to a byte > stream when calling putExtra() and re-created from that representation > when calling getSerializableExtra(), but I recently stumbled upon a > piece of code that put an entire view into a Bundle in thread A, > retrieved it from that bundle in thread B, performed a modification on > it and this modification actually became visible. This can only happen > if the reference to that view was stored, not the view itself, right? > Otherwise, the modification had been applied to a copy of that view > and would be meaningless. > > > -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---