5

i have bitmap in ActivityA i want to pass the bitmap from here to ActivityB, i googled for this. when i use this

Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("BitmapImage", bitmap);

for getting

Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");

i am getting this error !!! FAILED BINDER TRANSACTION !!! . how can i solve this problem.

RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98

4 Answers4

13

Your code is correct for putting bitmaps into the extras and works fine for me with small images. But it seems that there is a limit for the size of the Parcelable extra. See http://groups.google.com/group/android-developers/browse_thread/thread/7322a84adcfee567?pli=1.

You might want to store the image first and only hand over the URI to the store location.

Edit: Using a public static field for the bitmap as suggested by udaykiran violates so many OO principles I don't even know where to start.

ct_rob
  • 521
  • 3
  • 16
  • THANK YOU FOR THAT EDIT. I've downvoted the two answers that suggested it and left harsh comments, which I never do, because it's simply **terribad**. I wish I could upvote this a few more times. – salezica Jul 07 '12 at 01:45
3

I tried and its working as below using intent.putExtra("name", bitmap)

While passing with intent,

Intent intent = new Intent(Current.this, Next.class);
intent.putExtra("bmp", bitmap);
startActivity(intent);

While fetching,

Bitmap bitmap = getIntent().getParcelableExtra("bmp");

OR

Other option is to use Application class,

You can also use a class that extends Application and have a setter getter for Bitmap and call it from every Acitivity.

((myApplication_class_name)getApplication()).setBitmap(bmp);

and fetch the Bitmap using,

((myApplication_class_name)getApplication()).getBitmap();
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
1

I dont think that is the right method... you can use this link for the feature to be implemented. i too have used something like this itself.

Community
  • 1
  • 1
medampudi
  • 399
  • 3
  • 15
-5

You can simply name you Bitmap as static first.

then create a method like

public static Bitmap getBitmap(){
return bitmap;
}

then you can simply call from other activities,

bitmapwantedclass.getBitmap();

Hope it helps

Uday
  • 5,933
  • 9
  • 44
  • 76
  • i done as u said but getting error in the wanted class The method getBitmapCrop() is undefined for the type ImageAfterCrop – NagarjunaReddy Nov 24 '11 at 10:14
  • You have to call like this, suppose your bitmap is in class A and getBitmap is in A , you want that bitmap in class B, so you have to call A.getBitmap() in class B. – Uday Nov 24 '11 at 10:27
  • 17
    This is **awful** design, not a solution but a workaround, and the OP obviously did not have the knowledge to tell. I rarely downvote, but come on... – salezica Jul 07 '12 at 01:43
  • Why is he getting down voted? Sure it's not good design. But the standard way to write to disk then extract is extremely slow for high resolution photos even testing on new phones like the Nexus II. – Math is Hard Oct 26 '14 at 00:53