0

I'm trying to parce a list of Int.

I've tried this solution: How to parcel List<Int> with kotlin, but not worked

data class Pizza(
   var ingredients: ArrayList<Int>,
   val name: String,
   val imageUrl: String
) : Parcelable {
constructor(parcel: Parcel) : this(
        TODO("ingredients"),
        parcel.readString(),
        parcel.readString()) {
}

override fun writeToParcel(parcel: Parcel, flags: Int) {
    parcel.writeString(name)
    parcel.writeString(imageUrl)
}

override fun describeContents(): Int {
    return 0
}

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

    override fun newArray(size: Int): Array<Pizza?> {
        return arrayOfNulls(size)
    }
}
Wellington Yogui
  • 371
  • 3
  • 18
  • since youre using `Int` maybe this question here solves your problem... https://stackoverflow.com/questions/48371013/how-to-parcel-listint-with-kotlin?noredirect=1&lq=1 – Archie G. Quiñones Feb 18 '19 at 02:09

1 Answers1

2

Why don't you just try @Parcelize! Another cool feature of Kotlin.

Enable kotlin experimental in gradle

//Make sure you have adeed 
apply plugin: ‘kotlin-android-extensions’

androidExtensions {
    experimental = true
}

Then

@Parcelize
data class Pizza(
   var ingredients: ArrayList<Int>,
   val name: String,
   val imageUrl: String
) : Parcelable

Thats it.

Suyash Chavan
  • 776
  • 9
  • 20