1

Typically in java, objects are passed by the value of their reference. So if I have object OBJ at address addr then the object is passed by the value of the address addr. But recently I read on Stack Overflow (How can I pass a Bitmap object from one activity to another) that passing a bitmap through intent is expensive. Here is the partial quote:

If the bitmap exists as a file or a resource, its is always better to pass the URI or ResourceID of the bitmap and not the bitmap itself. Passing the entire bitmap requires a lot of memory.

So why is the bitmap object not being passed around by the value of its reference?

Community
  • 1
  • 1
learner
  • 11,490
  • 26
  • 97
  • 169

1 Answers1

0

Because an intent's target may not be in the same application. You can't pass a reference from one application to another, as they do not share memory. You can get around that with serialization, but that takes a lot of time and memory on both ends. The interface for an intent was written taking that into account, so it doesn't allow objects to be added to the Bundle except for certain simple types or objects that implement serializable (which Bitmap might, but passing it via intent would hit that large memory/time use).

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127