0

In Activity A, I download an image using Picasso and save into a Bitmap. I need that Bitmap in Activity B, how can I send it in the bundle without saving the image into the file system, and without sending the bitmap, as it's not very efficient?

EDIT: Is it possible to use the resource ID? If so, how?

Dani M
  • 1,173
  • 1
  • 15
  • 43
  • 3
    Possible duplicate of [How can I pass a Bitmap object from one activity to another](http://stackoverflow.com/questions/2459524/how-can-i-pass-a-bitmap-object-from-one-activity-to-another) – Roman Rozenshtein Jan 29 '16 at 21:54
  • As I said, I don't want to send the bitmap itself. – Dani M Jan 29 '16 at 22:06
  • "how can I send it in the bundle without saving the image into the file system" - you can send it in the bundle, without saving it into the file system that way. – Roman Rozenshtein Jan 29 '16 at 22:07
  • "how can I send it in the bundle without saving the image into the file system, and without sending the bitmap, as it's not very efficient?" – Dani M Jan 29 '16 at 22:12
  • I think you have a bit of a contradiction in your question, maybe edit it :) Any way, what you can do is save the bitmap in a singleton in your project or in the Application class and then fetch it from the other Activity. Though I will try and see if there is a problem with just passing it in the bundle in the first place. – Roman Rozenshtein Jan 29 '16 at 22:52

2 Answers2

0

If you strictly don't want to pass Bitmap to Bundle, you can extend Application class, and store/get bitmap to/from it. However, I'm asking you not to do this, and consider to send Bitmaps through Bundles, because storing such data in Application class is much worse then overhead from sending or storing in file system.

noktigula
  • 425
  • 6
  • 15
0

Bitmap implements Parcelable interface. So, you can pass it via bundle. For sending,

Intent intent = new Intent(CallingActivity.this, CalledActivity.class);
intent.putExtra("bitmap", bitmap);
startActivity(intent);

To retrieve it,

Bitmap bitMap = getIntent().getParcelableExtra("bitmap");
Gastón Saillén
  • 12,319
  • 5
  • 67
  • 77
Msp
  • 2,493
  • 2
  • 20
  • 34
  • It should work in theory, but you can get `E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!` for too large bitmaps. – serwus Aug 03 '20 at 17:01