-2

How can I pass an ImageView resource from one activity to another activity? Have tried imagview.resource and imageview.drawable to pass this data through intent. But neither works.

![enter image description here][1]

Below, I want to send image 1 to add in recyclerview of image 2.

![enter image description here][2]

  • Do you use `db` to load data in RecyclerView? add your model and adapter code to investigate – Md. Asaduzzaman Dec 06 '19 at 11:06
  • Passing the whole image resource is a bad idea. How are you getting the images? Are you getting it from a server or loading from app resources? – Froyo Dec 06 '19 at 13:47

3 Answers3

0

unreachable, but you can get the value you want by making imageview.setTag (key, tag) and then pulling it with the imageview.getTag() function.

Gorkem KARA
  • 173
  • 4
  • 14
0

Convert drawable to Bitmap and then into byte array form and then you can pass it via intent to another activity

See Below link : Passing image from one activity another activity

S.Ambika
  • 292
  • 1
  • 14
0

Convert Bitmap to Byte Array:-

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

Pass byte array into intent:-

Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("picture", byteArray);
startActivity(intent);

Get Byte Array from Bundle and Convert into Bitmap Image:-

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

Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);

image.setImageBitmap(bmp);
  • This is not an optimal approach. Intent has a limit of 1MB data. If the bitmap data is more than 1MB, it would crash the app. – Froyo Dec 06 '19 at 13:46