In my Android app, I want to add a Bundle including a Place
object described below to my Intent. Since serializable was slow and not recommended, I preferred Parcelable.
Althoug I use Kotlin 1.3.31, I have problems parcelizing some data classes. Example:
import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
@Parcelize
data class Place(val street: String, val postal: String, val city: String) : Parcelable
and Android Studio complains:
Class 'Place' is not abstract and does not implement abstract member public abstract fun writeToParcel(p0: Parcel!, p1: Int): Unit defined in android.os.Parcelable
According to some tutorials
That’s it! You don’t need to write any parcel methods anymore!
https://android.jlelse.eu/yet-another-awesome-kotlin-feature-parcelize-5439718ba220
and I do not want to use
androidExtensions {
experimental = true
}
in production stuff.
What alternatives would I have here?
A Parcelable is the Android implementation of the Java Serializable. It assumes a certain structure and way of processing it. This way a Parcelable can be processed relatively fast, compared to the standard Java serialization.
Parcelable is a serialization mechanism provided by Android to pass complex data from one activity to another activity.In order to write an object to a Parcel, that object should implement the interface “Parcelable“.
T { /* compiled code */ } } Class 'GetWelcomeMessageHandler' is not abstract and does not implement abstract base class member public abstract fun handleAPIGatewayRequest (input: APIGatewayProxyRequestEvent, context: Context?): WelcomeMessage I think you're just missing some override keywords.
To fix the Baby is not abstract and does not override abstract method speak () in Human error, the first solution is to override the abstract method canSpeak () in the Baby class that implements the Human interface.
This error appears because we have to override the abstract methods to define the body when implementing any class interface with abstract methods.
After the stable release of Kotlin 1.3.60 and its corresponding Android Studio plugin the issue is no more. Let's celebrate
After a bit of more researching and testing with the brand new Kotlin 1.3.50
seems that the issue is going to be finally fully addressed when they release Kotlin 1.3.60
as per this YouTrack issue
With Kotlin 1.3.40 release the @Parcelize
annotation is out of experimental and works quite nicely. The only issue is a reported issue that makes the IDE go red, leaving this to a side the code does compile and run perfectly.
I have also tested with this kind of objects and it does also work:
I'm facing the exact same issue and while investigating I found this:
So the looks like the @Parcelize
annotation will be fully stable starting from Kotlin 1.3.40
. Until then you will have to set the experimental
flag. (Sadly)
They have wrongly pushed @Parcelize
outside experimental features and you still get that compilation error.
In my scenario, I have already using the Kotlin plugin version latest than 1.3.40
version.
But I still got the Android Studio Error, compile success, but IDE complain about the @Parcelize
annotation.
Maybe you got this aswell.
Here is the solution.
Check your kotlin plugin version which you are configured in Gradle is the same version which bundled in Android Studio.
I got the error because my Gradle koltin plugin version is 1.3.61
and the Android Studio bundled version is 1.3.50
How to upgrade the Kotlin plugin version?
Tools -> Kotlin -> Configure kotlin plugin update
check the latest version and install, keep the two versions are the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With