Could anyone help me? I can’t find a way to proper...
# android
l
Could anyone help me? I can’t find a way to proper create a Parcelable
Copy code
data class ResultCache(val question: Int = 0,
                       val answer: Int = 0,
                       val value: String? = null,
                       val subQuestionResultCache: SubQuestionResultCache?) : Parcelable {
    companion object {
        @JvmField val CREATOR: Parcelable.Creator<ResultCache> = object : Parcelable.Creator<ResultCache> {
            override fun createFromParcel(source: Parcel): ResultCache = ResultCache(source)
            override fun newArray(size: Int): Array<ResultCache?> = arrayOfNulls(size)
        }
    }

    constructor(source: Parcel) : this(source.readInt(), source.readInt(), source.readString(), source.readParcelable(SubQuestionResultCache::class.java.classLoader))

    override fun describeContents() = 0

    override fun writeToParcel(dest: Parcel?, flags: Int) {
        dest?.writeInt(question)
        dest?.writeInt(answer)
        dest?.writeString(value)
        dest?.writeParcelable(subQuestionResultCache, 0)
    }
}
I’m trying this but apparently I’m doing something wrong with my
SubQuestionResultCache
type without it works just fine