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

HomeFragmentViewModel hold HomeActivity reference #47

Closed
baoti opened this issue Oct 21, 2017 · 3 comments
Closed

HomeFragmentViewModel hold HomeActivity reference #47

baoti opened this issue Oct 21, 2017 · 3 comments
Labels

Comments

@baoti
Copy link

baoti commented Oct 21, 2017

HomeFragmentViewModel is retained after screen rotated and HomeActivity recreated.
But HomeFragmentViewModel still hold old HomeNavigator (alsoHomeActivity) instance.

@chrisbanes chrisbanes added the bug label Oct 22, 2017
@chrisbanes
Copy link
Owner

Good catch.

@chrisbanes
Copy link
Owner

I've investigated this and what you described does not happen. Each fragment will get a new ViewModel created for it, which in turn gets the correct HomeNavigator.

Do you have any reproduction steps?

@chrisbanes
Copy link
Owner

OK, I lied. I was not seeing the issue due to #60, so a new fragment was being created every time. Fixing now.

chrisbanes pushed a commit that referenced this issue Nov 1, 2017
Currently it is injected via Dagger at VM creation.
This does not work at all when the Activity is rotated,
since the VM still be holding onto the old Activity
instance.

This commits refactors this to be based around a ViewModel
and a LiveData for each action. The ViewModel holds those
LiveDatas and the current Activity observes them. Each
fragment then retrieves the NavigatorViewModel and invokes
the LiveData's (through the interface).

Closes #47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants