I am using jetpack navigation for navigating. I observer the form submit with viewmodel livedata.
I am observing livedata in onActivityCreated of the fragment (SignUpFragment) like.
viewModel.signup.observe(viewLifecycleOwner, Observer<Resource<BaseResponse<User>>> {
checkSignUpResponse(it)
})
after i am navigated to the next fragment (OtpFragment) when i am using navigationUp() sign up observer called method in observer (checkSignUpResponse) and sending me to otp fragment again.
i tried
viewModel.signup.removeObservers(viewLifecycleOwner)
and also
viewModel.signup.removeObserver(signUpObserver)
but it doesn't work.
I have just used isNavigatedToOtp boolean switched while navigating n check weather is isNavigatedToOtp false n then called checkSignUpResponse.