hi guys, is this the right way to use `@Parcelize`...
# android
m
hi guys, is this the right way to use
@Parcelize
on kotlin sealed classes:
Copy code
sealed class MySealedClass : Parcelable {
    @Parcelize object Object1: MySealedClass()
    @Parcelize object Object2: MySealedClass()
    @Parcelize object Object3: MySealedClass()
}
I am getting the error:
Copy code
android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.myapp.data.MySealedClass$Object1
when try to create the Intent….
a
i think it needs to be a data class. sealed classes and parcellable will require you to provide your own implementations for write to parcel and other methods
c
I would also maybe reconsider using parcelables at all. Passing parcelables is widely accepted is an anti pattern.
k
@Parcelize
works with sealed class. Did you set the
classLoader
? Where is the exception thrown?
m
@Colton Idle I am not using it with the Jetpack Navigation framework, I am using it to pass data inside my own created Bundle instance, and I don’t know why the Parcelable creation is failing, @knthmn yeah it should works, I am wondering if this is some Issue with the kotlin
object
key 🤔
k
if you use
Bundle
you need to set
classLoader
before calling
getParcelable()
m
@knthmn the issue happens before the reading part of the bundle, specifically it is on the calling of the
.startActivity()
method on the Activity class…
I mean, my Intent parse code on the other Activity is not being reached.
188 Views