1

I need to send a specific image from my recyclerview that has been clicked to the new activity that will display the image. The question is how do I convert my image to bitmap or something like that so I can send them using intent? Here's my code:

RecyclerViewAdapter.kt

class ViewHolder(view: View) : RecyclerView.ViewHolder(view){

    fun bindItem(items: Item) {
        itemView.name.text = items.name
        itemView.desc.text = items.desc
        Glide.with(itemView.context).load(items.image).into(itemView.image)

        itemView.setOnClickListener {
            itemView.context.startActivity(itemView.context.intentFor<DetailsActivity>("image" to bitmap, "name" to items.name, "desc" to items.desc))
        }
    }
}

SecondActivity

val intent = intent
    name = intent.getStringExtra("name")
    image = intent.getStringExtra("image")
    desc = intent.getStringExtra("desc")

    nameTextView.text = name
    descTextView.text = desc
    Glide.with(this)
            .load(image)
            .into(imgPhotos)

I have already tried all the code that are provided on this site, but they all didn't work. Thanks!

Rayhan Hanaputra
  • 106
  • 2
  • 16

2 Answers2

1

I am not using Glide but it should be like this.

 lateinit imageBitmap : Bitmap

 Glide.with(this).asBitmap().load("YOUR_URL").into(object: Target<Bitmap>{
      override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
          imageBitmap = resource
      }
 })

You can send Bitmap directly because it is Parcelable

intent.putExtra("image",imageBitmap)

To getBitmap

val bitmap  = intent.extras.getParcelable<Bitmap>("image")
Ferhat Ergün
  • 135
  • 1
  • 10
0

Convert the image to byteArray and pass it through intent. Extract the data through intent on the other side and convert byteArray into bitmap.

Prashanth Verma
  • 588
  • 3
  • 11