Skip to content

Instantly share code, notes, and snippets.

@dilrajsingh1997
Created Dec 2, 2021
Embed
What would you like to do?
data class User(
val id: Int,
val name: String
) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readString() ?: ""
)
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(id)
parcel.writeString(name)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<User> {
override fun createFromParcel(parcel: Parcel): User {
return User(parcel)
}
override fun newArray(size: Int): Array<User?> {
return arrayOfNulls(size)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment