Skip to content Skip to sidebar Skip to footer

Passing View With Intent

I want to passing my viewto update my view in other activity. This is my code to passing view. emp_photo_edit.setOnClickListener(new View.OnClickListener() { @Override

Solution 1:

Arguments passed to the bundle should implement the Serializable or Parcelable interface. The LinearLayout doesn't. The best solution is to pass the data inside the view to the Intent and apply that to a view in the receiving Activity

Solution 2:

You can not pass a view (imageview) in intent.

You should pass image bitmap as ByteArray or Parcelable in intent like below.

Pass bitmap as ByteArray:

First Convert image into ByteArray and then pass into Intent and in next activity get ByteArray from Bundle and convert into image(Bitmap) and set into ImageView.

Convert Bitmap to ByteArray and pass into Intent:-

Bitmapbmp= BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStreamstream=newByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

Intentintent=newIntent(this, NextActivity.class);
intent.putExtra("picture", byteArray);
startActivity(intent);

Get ByteArray from Bundle and convert into Bitmap image:-

Bundleextras= getIntent().getExtras();
byte[] byteArray = extras.getByteArray("picture");

Bitmapbmp= BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageViewimage= (ImageView) findViewById(R.id.imageView1);

image.setImageBitmap(bmp);

OR

Pass bitmap as Parcelable:

Pass Bitmap directly into Intent as Parcelable extra and get bitmap as Parcelable extra in next activity from Bundle, but the problem is if your Bitmap/Image size is big at that time the image is not load in next activity.

Checkout get ImageView's image and send it to an activity with Intent

Post a Comment for "Passing View With Intent"