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

Observer is called on load of Fragment Using Navgraph #4

Open
Mujas opened this issue Aug 7, 2020 · 0 comments
Open

Observer is called on load of Fragment Using Navgraph #4

Mujas opened this issue Aug 7, 2020 · 0 comments

Comments

@Mujas
Copy link

Mujas commented Aug 7, 2020

Known issue in all blogs.

I have Fragment A and Fragment B, called Fragment B and inside this i have one api call and I am observing the Livedata. I got the response from API and its working fine. I navigateUp to Fragment A and come back again to Fragment B, again the last observer trigers. Even though am removing the observer and creating new.

Fragment B:

private val viewModel : MyViewModel by activityViewModels()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel .getData().removeObservers(viewLifecycleOwner)
viewModel .getData().observe(viewLifecycleOwner, Observer {
navController.navigateUp() // this calls again and again
})
}

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

1 participant