Closed jQrgen closed 5 years ago
I would be surprised if you can. MxRx
relies on Jetpack ViewModel
and Google recommends using a single Activity
approach because you can share ViewModel
.
@jQrgen No, MvRx does not support this out of the box. If you want to build your own system or have a ViewModel on your Application/Dagger graph, you can do that as you see fit.
So if i use MvRxViewModel for keeping a global state such as the state of a user i should just initiate it in the fragment identified in nav_graph.xml's app:startDestination="
What do you guys use for approaching this? A viewModel initiated in MainActivity?
@jQrgen Well if you want it to persist across activities, you can't instantiate it in a Fragment. You can try having one in your dagger/DI graph with a @Singleton
scope or something.
Is it possible to share state inbetween activites? I get errors when trying to access a viewmodel in an activity.