Sayyaf Sayyaf - 1 year ago 148
Android Question

How to send the bitmap into bundle

I'm new to android. I want to pass bitmap into bundle. But i cant find any solution for it. Actually I'm confused. I want to display an image in an Dialog fragment. But i dont know how to put into bundle? should i send as PutByteArray()? But if i pass bitmap as an argument. it is stating wrong argument. here is my code "

`public class MyAlert extends DialogFragment {
Bitmap b;
public MyAlert newInstance(Bitmap b)
MyAlert frag=new MyAlert();
Bundle args=new Bundle();
return frag;

public Dialog onCreateDialog(Bundle savedInstanceState) {
Bitmap bitmap=getArguments().getByteArray("bitByte");
return new AlertDialog().Builder(getActivity());
AlertDialog.Builder builder=new AlertDialog.Builder(getActivity()).setView(;`

tpA tpA
Answer Source

First of all convert it to a Byte array before adding it to intent, send it out, and decode.

//Convertion to byte array

  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
  byte[] byteArray = stream.toByteArray();

Bundle b = new Bundle();

  // your fragment code 

get Value via intent

byte[] byteArray = getArgument().getByteArrayExtra("image");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download