简体   繁体   中英

android fragment livedata remove observer not working

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM