0

I am trying to send a Bitmap with Intent from a RecyclerView adapter to an Activity. The error I get is: FAILED BINDER TRANSACTION !!! (parcel size = 6010104). Can anyone find what is wrong? My code is below.

class ClothesAdapter(private var clothesList: List<ClothModel>) :
        RecyclerView.Adapter<ClothesAdapter.MyViewHolder>() {

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        var titleView: TextView = view.findViewById(R.id.title_view)
        var imageView: ImageView = view.findViewById(R.id.image_view)
    }

    @NonNull
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {

        val itemView = LayoutInflater.from(parent.context)
                .inflate(R.layout.cloth_row, parent, false)
        return MyViewHolder(itemView)
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {

        val cloth = clothesList[position]
        holder.titleView.text = cloth.getTitle()
        holder.imageView.setImageBitmap(cloth.getBitmap())

        var context = holder.itemView.context

        holder.imageView.setOnClickListener {

            val clothBitmap = cloth.getBitmap()!!

            val bStream = ByteArrayOutputStream()
            clothBitmap?.compress(Bitmap.CompressFormat.PNG, 100, bStream)
            val byteArray: ByteArray = bStream.toByteArray()
            val intent = Intent(context, StillImageActivity::class.java)
            intent.putExtra("bitmap", byteArray)
            context.startActivity(intent)   //AT THIS POINT I GET ERROR
        }
    }

    override fun getItemCount(): Int {
        return clothesList.size
    }

}
Onik
  • 19,396
  • 14
  • 68
  • 91
ktsakiris
  • 59
  • 1
  • 10

1 Answers1

1

Can anyone find what is wrong?

Most likely TransactionTooLargeException is the reason.

Instead of putting ByteArray to an Intent, write it to a file and put the file URI to the Intent. Later in the Activity read the ByteArray from the file using the URI passed.

Onik
  • 19,396
  • 14
  • 68
  • 91