Hi, I can't seem to pass my parcelable arrays to o...
# announcements
s
Hi, I can't seem to pass my parcelable arrays to other activity, so is there anyone who can help me out/
g
Parcelable array? Array of parcelables?
Could you please show your code
s
data class RoutesResponse(@SerializedName("result") val result: String, @SerializedName("freason") val freason: String, @SerializedName("route") var routesList: MutableList<RouteObject>, @SerializedName("route_site") var routeSiteList: MutableList<RouteSite>) : Parcelable { companion object { @JvmField val CREATOR: Parcelable.Creator<RoutesResponse> = object : Parcelable.Creator<RoutesResponse>{ override fun createFromParcel(p0: Parcel): RoutesResponse = RoutesResponse(p0) override fun newArray(p0: Int): Array<RoutesResponse?> = arrayOfNulls(p0) } } constructor(source: Parcel) : this(source.readString(), source.readString(), source.createTypedArrayList(RouteObject.CREATOR), source.createTypedArrayList(RouteSite.CREATOR)) override fun describeContents() = 0 override fun writeToParcel(p0: Parcel?, p1: Int) { p0?.let { with(it){ writeString(result) writeString(freason) writeTypedList(routesList) writeTypedList(routeSiteList) } } } }
the other two models of type RouteSite and RouteObject have similar parcelable implementation
I'm sending the list like this:
val testList = getRelevantRoutes(it.id) toast (testList.size.toString()) startActivity(intentFor<GatewayActivity>(KEY_ROUTE_SITES to testList))
and recieving using this: val siteListFromIntent = intent.getParcelableArrayExtra("routesSiteList")[0]
I'm geting source.readString can not be null when i try to read from intent. I'll drop using anko if there's a work around
g
So what is error in your case?
Maybe source.readString is really null
s
how can i fix it?
java.lang.IllegalStateException: source.readString() must not be null
g
So string is null, it means that Parcel has no string in first position
s
but the list is showing up in the activity from where I want to send my list
g
Try to debug your intent
s
and also I'm getting it from the webservice
ok
how do you send intents to one kotlin activty to another and how do you read the?
g
Exactly the same way as in java
s
in Kotlin? give me that line of code
and do you implement Parcelable the way I've tried to do?
g
I do not implement Parcelable manually
Same way in kotlin, just copy paste
s
have you used @Parcelize?
g
no
but it’s definitely nothing wrong to implement it manually
Are you sure that you need getParcelableArrayExtra? val siteListFromIntent = intent.getParcelableArrayExtra(“routesSiteList”)[0]
because looks like you send list instead of array
there is getParcelableArrayListExtra