I am running into a weird problem . I have a class A which implements Parcelable interface in kotlin.
I am passing the array of class A from one activity to another no issues here.
var arrayOfA:Array<A> // just to tell the type assume the array is initialised with the value
intent.putExtra("array", arrayOfA)
But while receiving it in another activity , I am not able to assign it to variable of type Array it is asking me to assign it to Array when A is on type parcelable why I am not able to assign it the variable.
in second Activity
var arrayOfA:Array<A>?=null
arrayA=intent.get("array") as Array<A> // Problem here. Class cast exception
I am not able to understand why. Can some one help me here. I don't want to change the type of variable to Array as it as many inter depedencies.(The class here is just a demonstration)
========================================
class A(val a:String?,val b:String?):Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString(),
parcel.readString()) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(a)
parcel.writeString(b)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<A> {
override fun createFromParcel(parcel: Parcel): A {
return A(parcel)
}
override fun newArray(size: Int): Array<A?> {
return arrayOfNulls(size)
}
}
}