0

This is MainActivity code

val bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test)
val stream = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream)
val byteArray = stream.toByteArray()

val intent = Intent(this@Math1Activity, test::class.java)
intent.putExtra("image",byteArray)
startActivity(intent)
overridePendingTransition(0, 0)

This is SecondActivity code

val byteArray = getIntent().getByteArrayExtra("image")
if(byteArray != null){
    val image = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size)
    binding.testimage.setImageBitmap(image)
}

I want to send more than two images with intents. But I only know one way to transform a bitmap. Let me know if there's a good way to intent more than two image.

Axe319
  • 4,255
  • 3
  • 15
  • 31
WONDDAK
  • 1
  • 1
  • from where you will get these images in your First Activity ?note that the max size you can send it is limited chek the official [doc](https://developer.android.com/guide/components/activities/parcelables-and-bundles#sdba) – Shay Kin Mar 16 '21 at 11:32
  • its not best practice to send images like this through intents, they may be larger in size, you can save them in temporary paths on your device, and later send the path to other activity and clear those temp paths. kindly check this answer https://stackoverflow.com/a/24631097/5088314 – M. Bilal Asif Mar 16 '21 at 12:30
  • Thank you. Thanks to you, I solved it well. – WONDDAK Mar 17 '21 at 00:38

0 Answers0