Search code examples
androidandroid-bundle

How does Bundle works?


I'm not asking how do I use it nor what does it do, how does it works. The question came to me when I though why didn't they just put a putExtra(String,Object) so I can pass an object. Obviously they just didn't forgot to do it, rather than the way Bundle works isn't one you can just do that.

PS: Serializable or Parcelable is something you cannot implement on every class you create, so they are not a replacement for putExtra(String,Object)


Solution

  • Obviously they just didn't forgot to do it

    Correct.

    A Bundle itself is Parcelable, as Doctoror Drive notes. The point behind a Parcelable is to be able to place it into a Parcel, and the point behind a Parcel is to pass the data across process boundaries. You cannot pass arbitrary objects across process boundaries, just as you cannot write arbitrary objects to a file and cannot stream arbitrary objects over a socket.