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

Sharing state inbetween activities #119

Closed
jQrgen opened this issue Oct 15, 2018 · 4 comments
Closed

Sharing state inbetween activities #119

jQrgen opened this issue Oct 15, 2018 · 4 comments

Comments

@jQrgen
Copy link

jQrgen commented Oct 15, 2018

Is it possible to share state inbetween activites? I get errors when trying to access a viewmodel in an activity.

@qbait
Copy link

qbait commented Oct 15, 2018

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.

@gpeal
Copy link
Collaborator

gpeal commented Oct 15, 2018

@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.

@gpeal gpeal closed this as completed Oct 15, 2018
@jQrgen
Copy link
Author

jQrgen commented Oct 15, 2018

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?

@gpeal
Copy link
Collaborator

gpeal commented Oct 16, 2018

@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.

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

3 participants