How to transfer a bitmap from one activity to another

I have a bitmap in ActivityA. I want to transfer a bitmap from here to ActivityB, for which I googled. when i use this

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

to receive

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

I get this error !!! FAULT TRANSACTIONS WITH DISKS !!! . how can i solve this problem.

+4
source share
4 answers

You can simply call you Bitmap as static .

then create a method like

 public static Bitmap getBitmap(){ return bitmap; } 

then you can just call from other activities,

 bitmapwantedclass.getBitmap(); 

Hope this helps

-5
source

Your code is correct for setting bitmap images to advanced features and works great for me with small images. But it seems that there is a size limit to Parcelable extra. See http://groups.google.com/group/android-developers/browse_thread/thread/7322a84adcfee567?pli=1 .

You can save the image first and only pass the URI to the store.

Edit: using an open static field for a bitmap, as suggested by udaykiran, violates so many OO principles, I don’t even know where to start.

+12
source

I tried and worked as shown below with intent.putExtra("name", bitmap)

When passing with the intention

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

When retrieving,

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

OR

Another option is to use the Application class,

You can also use a class that extends Application , and it has a setter receiver for Bitmap and calls it from any Acitivity.

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

and select a bitmap using

 ((myApplication_class_name)getApplication()).getBitmap(); 
+3
source

I do not think this is the right method ... you can use this link for the function to be implemented. I also used something similar.

+1
source

Source: https://habr.com/ru/post/1382858/


All Articles