为了使用Parcelable,我遵循了Kotlin 1.1.4:https://blog.jetbrains.com/kotlin/2017/08/kotlin-1-1-4-is-out/的这个版本
Add this line in project
androidExtensions {
experimental = true
}
Then define a class :
@Parcelize
class User(val firstName: String, val lastName: String) : Parcelable
writeToParcel()和createFromParcel()方法是自动创建的
override fun writeToParcel(parcel: Parcel, flags: Int) {
...
}
but still have an error in 'override' keyword with message
OVERRIDING_WRITE_TO_PARCEL_IS_NOT_ALLOWED: Overriding 'writeToParcel' is not allowed. Use 'Parceler' companion object instead
Can you show me the right way?
Edit :
PROPERTY_WONT_BE_SERIALIZED: Property would not be serialized into a 'Parcel'. Add '@Transient' annotation to remove the warning