[英]android fragment livedata remove observer not working
I am using jetpack navigation for navigating.我正在使用喷气背包导航进行导航。 I observer the form submit with viewmodel livedata.
我用 viewmodel livedata 观察表单提交。
I am observing livedata in onActivityCreated of the fragment (SignUpFragment) like.我正在观察片段(SignUpFragment)的onActivityCreated中的livedata。
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.在我导航到下一个片段(OtpFragment)后,当我使用navigationUp()注册观察者称为观察者(checkSignUpResponse)中的方法并再次将我发送到otp片段。
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.我刚刚使用 isNavigatedToOtp boolean 在导航时切换 n 检查天气是 isNavigatedToOtp false n 然后调用 checkSignUpResponse。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.