To use Parcelable, I followed this Kotlin 1.1.4 release: https://blog.jetbrains.com/kotlin/2017/08/kotlin-1-1-4-is-out/
Add this line to the project
androidExtensions { experimental = true }
Then define the class:
@Parcelize class User(val firstName: String, val lastName: String) : Parcelable
The writeToParcel () and createFromParcel () methods are created automatically
override fun writeToParcel(parcel: Parcel, flags: Int) { ... }
but there is still an error in the 'override' key with the message
OVERRIDING_WRITE_TO_PARCEL_IS_NOT_ALLOWED: Overriding 'writeToParcel' is not allowed. Use the helper object "Parceler" instead
Can you show me the right way?
Edit: Will only the properties defined in the default constructor be added to Parcel, but not others? I see this warning in this class.
PROPERTY_WONT_BE_SERIALIZED: The property will not be serialized to 'Package'. Add @Transient annotation to remove warning
android kotlin parcelable
quangkid
source share