Meo11
Meo11

Reputation: 3

How can I pass an arraylist that contains a bitmap to another activity in Kotlin?

So this is my class:

class Pricecard(val img: Bitmap?, val title: String?, val weight: String?, val price: String?, val code: String?) : Parcelable {
    constructor(parcel: Parcel) : this(
        parcel.readValue(),   //this is giving an error
        parcel.readString(),
        parcel.readString(),
        parcel.readString(),
        parcel.readString(),
    ) {
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeString(img)  //this is giving an error
        parcel.writeString(title)
        parcel.writeString(weight)
        parcel.writeString(price)
        parcel.writeString(code)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<Pricecard> {
        override fun createFromParcel(parcel: Parcel): Pricecard {
            return Pricecard(parcel)
        }

        override fun newArray(size: Int): Array<Pricecard?> {
            return arrayOfNulls(size)
        }
    }
}

I want to know how to pass the Bitmap image to this activity so I can show it with the other variables from the object. This has to be in a list, because there are multiple pricecards that I want to show.

I tried to use Parcelable but it did not work because of those errors. I expected it to work properly.

Upvotes: 0

Views: 72

Answers (0)

Related Questions