Hello! I started to use Voyager for navigation. As...
# multiplatform
e
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
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
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
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
Thank you, I will try to figure out how to move all the possible logic to the viewmodel. It鈥檚 being tough 馃槃
a
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
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
鈽濓笍
106 Views