Reputation: 42652
I am developing Android project in Kotlin. I want to create a model class that implements Parcelable interface. This is what I tried:
@Parcelize
data class School(
@Expose val name: String?,
@Expose val address: String?,
): Parcelable
But I get compiler error saying that "Class School is not abstract and does not implement abstract memeber public abstract fun writeToParcel(p0: Parcel!, p1: Int):Unit
defined in android.os.Parcelable
".
I understand what the error is saying. But how to get rid of this error? My Kotlin version is 1.3.50
Upvotes: 3
Views: 3676
Reputation: 472
check you have Added this
androidExtensions {
experimental = true
}
and try to implement Parcelable like this
class School(var name:String, var address:String):Parcelable
pass data like this
val school = School("demo","demo")
val intent = Intent(this, activityB::class.java)
intent.putExtra("schooldata",school)
startActivity(intent)
get like this
var school = intent.extras.getParcelable<School>("schooldata")
schooldata.setText("${school.name}"+"\n"+"${school.address}")
Upvotes: 0
Reputation: 1031
Add
androidExtensions {
experimental = true
}
to your Android block within your app build.gradle.
Upvotes: 2