Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parcelize parcelable objects #78

Closed
lcsphantom opened this issue Aug 10, 2022 · 11 comments
Closed

Unable to parcelize parcelable objects #78

lcsphantom opened this issue Aug 10, 2022 · 11 comments

Comments

@lcsphantom
Copy link

lcsphantom commented Aug 10, 2022

In the documentation here we are explained to use @parcelize and Parcelable however when doing so, the app throws an exception when you tap home, leave the app or open another Intent:

FATAL EXCEPTION: main Process: ca.redacted, PID: 10491 java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = ca....redacted) at android.os.Parcel.writeSerializable(Parcel.java:2125) at android.os.Parcel.writeValue(Parcel.java:1895) at android.os.Parcel.writeList(Parcel.java:1104) at android.os.Parcel.writeValue(Parcel.java:1844) at android.os.Parcel.writeList(Parcel.java:1104) at android.os.Parcel.writeValue(Parcel.java:1844) at android.os.Parcel.writeArrayMapInternal(Parcel.java:987) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1620) at android.os.Bundle.writeToParcel(Bundle.java:1303) at android.os.Parcel.writeBundle(Parcel.java:1056) at android.os.Parcel.writeValue(Parcel.java:1813) at android.os.Parcel.writeArrayMapInternal(Parcel.java:987) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1620) at android.os.Bundle.writeToParcel(Bundle.java:1303) at android.os.Parcel.writeBundle(Parcel.java:1056) at android.os.Parcel.writeValue(Parcel.java:1813) at android.os.Parcel.writeArrayMapInternal(Parcel.java:987) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1620) at android.os.Bundle.writeToParcel(Bundle.java:1303) at android.app.IActivityTaskManager$Stub$Proxy.activityStopped(IActivityTaskManager.java:4969) at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:145) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:246) at android.app.ActivityThread.main(ActivityThread.java:8645) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) Caused by: java.io.NotSerializableException: ca...redacted at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1240) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1604) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1565) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1488) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:354) at android.os.Parcel.writeSerializable(Parcel.java:2120) at android.os.Parcel.writeValue(Parcel.java:1895)  at android.os.Parcel.writeList(Parcel.java:1104)  at android.os.Parcel.writeValue(Parcel.java:1844)  at android.os.Parcel.writeList(Parcel.java:1104)  at android.os.Parcel.writeValue(Parcel.java:1844)  at android.os.Parcel.writeArrayMapInternal(Parcel.java:987)  at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1620)  at android.os.Bundle.writeToParcel(Bundle.java:1303)  at android.os.Parcel.writeBundle(Parcel.java:1056)  at android.os.Parcel.writeValue(Parcel.java:1813)  at android.os.Parcel.writeArrayMapInternal(Parcel.java:987)  at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1620)  at android.os.Bundle.writeToParcel(Bundle.java:1303)  at android.os.Parcel.writeBundle(Parcel.java:1056)  at android.os.Parcel.writeValue(Parcel.java:1813)  at android.os.Parcel.writeArrayMapInternal(Parcel.java:987)  at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1620)  at android.os.Bundle.writeToParcel(Bundle.java:1303)  at android.app.IActivityTaskManager$Stub$Proxy.activityStopped(IActivityTaskManager.java:4969)  at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:145)  at android.os.Handler.handleCallback(Handler.java:938)  at android.os.Handler.dispatchMessage(Handler.java:99)  at android.os.Looper.loop(Looper.java:246)  at android.app.ActivityThread.main(ActivityThread.java:8645)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) 

In fact the example given in the documentation doesn't work.
Versions used:

val voyager_version = 1.0.0-rc02

    implementation "cafe.adriel.voyager:voyager-navigator:$voyager_version"
    implementation "cafe.adriel.voyager:voyager-androidx:$voyager_version"
    implementation "cafe.adriel.voyager:voyager-hilt:$voyager_version"

id org.jetbrains.kotlin.android version 1.7.0 apply false

  ext {
        compose_ui_version = 1.2.0-rc01
        compose_compiler_version = 1.2.0
   }

I did see this thread: ##59 but even when using something like:

@Parcelize
data class NavParam(
    var firstName: String = "",
): Parcelable

data class NewScreen(
    val navParam: NavParam
) : Screen {
}

The app still crashes.

@DjakaTechnology
Copy link

I also encountered this, for now I add Serializable into the mix to workaround this issue

@parcelize
data class NavParam(
var firstName: String = "",
): Parcelable, Serializable

@arslan-charyyev-pc
Copy link
Contributor

arslan-charyyev-pc commented Dec 10, 2022

Can confirm that this issue is still present in the latest version (1.0.0-rc03).

Take the example from documentation: https://voyager.adriel.cafe/state-restoration

// ✔️ DO
@Parcelize
data class Post(/*...*/) : Parcelable

data class ValidScreen(
    val userId: UUID, // Built-in serializable types
    val post: Post // Your own parcelable and serializable types
) : Screen {
    // ...
}

This "DO" example will actually lead to a crash whenever ValidScreen has to be parcelized, such as when activity goes into background. The solution by @DjakaTechnology does indeed mitigate the issue.

@zakrodionov
Copy link

@adrielcafe @DevSrSouza @Syer10
I tagged you guys, because you are the main maintainers of the code.
Please see this issue🙏🙏🙏

@Kashif-E
Copy link
Contributor

Kashif-E commented Apr 4, 2023

Facing this on 1.0.0-rc02

@Kashif-E
Copy link
Contributor

Kashif-E commented Apr 4, 2023

if some one using it in a kmm app. you can do expect actual to get java.io.Serilizable

actual typealias CommonSerializable = java.io.Serializable

expect CommonSerializable

and then

data class SomeClass(val foo: String) : CommonSerializable

@ghostmane0404
Copy link

1.0.0-rc04 and it is still present. @adrielcafe is there any new on this theme?

@DevSrSouza
Copy link
Collaborator

The documentation was misleading, we have updated it with more samples and Multiplatform notice.
https://voyager.adriel.cafe/state-restoration

@KapilYadav-dev
Copy link

Any update on this guys ????

@Kashif-E
Copy link
Contributor

Kashif-E commented Aug 2, 2023

@KapilYadav-dev i have updated my comment that solves this issue

@KapilYadav-dev
Copy link

@Kashif-E what about desktop and ios for their platform?

@DevSrSouza
Copy link
Collaborator

@KapilYadav-dev is just a plain interface in this case

actual interface CommonSerializable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants