2

Consider a,b,c,d,e are all strings that aren't null.
I have an object called data that holds the URLs for image and prev_image.

There's an activity named Games, leading to "MyActivity".

My problem is as such:
If I try to "putextra" both bitmaps, I end up in "Games", no errors given, no exceptions, no nothing. If I comment out the line where I add "image" to the bundle, then everything works. But I need image in a later activity. so I must have it there. I tried scaling it down but it didn't help, it doesn't seem like a memory issue, but... I could be wrong :)

Bitmap temp = BitmapFactory.decodeStream((new URL(data.getString("image"))).openStream());
image = image = Bitmap.createScaledBitmap(image,300,300,true);

temp = BitmapFactory.decodeStream((new URL(data.getString("image"))).openStream());
prev_image = Bitmap.createScaledBitmap(image,300,300,true);

temp.recycle();

Intent intent = new Intent(MyActivity.this,NextActivity.class);
intent.putExtra("a",a);
intent.putExtra("b",b);
intent.putExtra("c",c);
intent.putExtra("d",d);
intent.putExtra("e",e);
intent.putExtra("image",image);
intent.putExtra("prev_image",prev_image);
startActivity(intent);

Any help would be much appreciated.

Edit:

I figured I'd add the solution I used for my app.
What I ended up doing was save the bitmaps as files and just pass the URI's to the files between activities and only load the bitmaps in activities that need them.
And of course, eventually deleting the files.

Chen Doron
  • 106
  • 6
  • are you sure image and prev_image are not null? A suggestion: recycling once temp is not enough. You have to recycle it two times or leaks can occur – Blackbelt Dec 09 '12 at 17:38
  • 1
    it would be much better to pass just a string url to an intent and pass it to your next activity. than you will be able to fetch this image from this url instead of passing whole image in extras. – fgeorgiew Dec 09 '12 at 17:39
  • [This question](http://stackoverflow.com/questions/2459524/how-can-i-pass-a-bitmap-object-from-one-activity-to-another) might be useful. Last answer mentions JAVA BINDER FAILURE error, that might occur... – Vajk Hermecz Dec 09 '12 at 17:46
  • I would add the logcat if there was anything there, but nothing happens...I just go back to the previous activity I was on and there aren't any errors.
    I don't want to download the bitmap on the next intent because the current intent is a "loader" that is meant to save the loading time on the next intent.
    – Chen Doron Dec 09 '12 at 17:48
  • Vajk Hermecz, Why is it different to attach the bitmap as a parceable rather than as a ByteArray ? – Chen Doron Dec 09 '12 at 17:51

1 Answers1

0

There is a maximum size to the data that can be sent in an intent. Your bitmap probably exceeds it. It's about 50Kb

MrChaz
  • 1,065
  • 1
  • 8
  • 17
  • Is there a way I can find out if I've exceeded that size ? I have two bitmaps 300x300 big, and a couple of strings... It doesn't seem like I'm past 1Mb... – Chen Doron Dec 09 '12 at 17:49
  • I think something appears in logcat. A bit of googling seems to suggest a 50k limit – MrChaz Dec 09 '12 at 17:56
  • Cool, thanks...I think I'll have to figure out a different way to pass the bitmap to the next intent. – Chen Doron Dec 09 '12 at 18:08
  • Pass image uri in extras and get image from uri in other activity instead of passing actual image..,. – MKB Dec 10 '12 at 05:40
  • And if I pass the URI and work like that, when is it safe to recycle the bitmaps I'm using ? – Chen Doron Dec 10 '12 at 08:00