https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
e

Enol Simón

02/28/2024, 9:40 AM
Hello! I started to use Voyager for navigation. As I am still migrating an Android app to Multiplatform, I still need to pass some functions as argument from the activity to the Composable function. It makes Voyager to crash when I navigate to another activity, or I open a link via Intent with the error
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object
. I have read that it is a problem because of this . Anybody has a solution or knows how I can pass certain arguments without getting this error?
a

Andrew Watson

02/28/2024, 6:35 PM
Any arguments passed to your
Screen
classes have to be either serializable or parcelable. Simple values like strings, ints, etc will work without problem
are you trying to instantiate/inject your viewmodel?
e

Enol Simón

02/28/2024, 10:51 PM
Yes I'm doing it, however I need to define some functions inside the activity and pass them as argument to the composables, because they are using an activity context, and I can not get that from the view model or through an
expect/actual
declaration
a

Andrew Watson

02/28/2024, 10:51 PM
Yeah it's just the viewmodel you can't inject in the constructor of the screen
You have to do that in the
Content()
method
e

Enol Simón

02/29/2024, 8:57 AM
Thank you, I will try to figure out how to move all the possible logic to the viewmodel. It’s being tough 😄
a

Andrew Watson

02/29/2024, 6:24 PM
Well remeber, you can pass simple things to the screen - strings, numbers etc. If you need something more complex, you'll need other methods
v

Vlad

02/29/2024, 7:03 PM
I don't know the nature of your callbacks but you probably can play around it. You can create some component and install it into LocalComposition, and then access it from anywhere down the tree. The same thing could be done without using compose and via some shared between your activity and a screen viewmodel instance.
👍 1
a

Andrew Watson

02/29/2024, 7:03 PM
☝️
28 Views