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

Bug : ViewmodelProvider returns different instance of VM for Activity and Fragment #202

Closed
savant-martins opened this issue Oct 11, 2017 · 2 comments

Comments

@savant-martins
Copy link

Support lib v7:26.1.0
Architecture components beta2

VM created in Activity using
stockcheckViewModel = ViewModelProviders.of(this).get(StockcheckViewModel.class);

And in fragment (from onCreateView)
stockcheckViewModel = ViewModelProviders.of(getActivity()).get(StockcheckViewModel.class);

Fragment created in activity using getSupportFragmentManager()

Stepping through the code it seems that the ViewModelProvider creates a different stores instance for the Activity and Fragment

https://stackoverflow.com/questions/46574672/lifecycle-viewmodel-not-shared-between-activity-and-fragments

@yigit
Copy link
Contributor

yigit commented Oct 19, 2017

in your samples, i don't see where initViewModel is called. If you are calling it before onCreate, you might end up in this situation.

@ianhanniballake
Copy link
Contributor

Please file issues with ViewModel on the issue tracker with a sample project that reproduces your issue.

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