I added Parcelable implementation for my class and get this code:
data class Category (val name:String, var factors:ArrayList<String>):Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString(),
TODO("factors")) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(name)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<Category> {
override fun createFromParcel(parcel: Parcel): Category {
return Category(parcel)
}
override fun newArray(size: Int): Array<Category?> {
return arrayOfNulls(size)
}
}
}
As far as I understand I should write method for reading data from ArrayList. I've tried to use
parcel.readArrayList()
but can not understand, how to insert String as ClassLoader. Please help me to understand, how to make this object Parcelable.