Describe the bug
I'm not sure if this is a koin bug or LiveData bug or even a bug in general!
I'm using Jetpack Navigation with one activity and bunch of framents and a view model which is shared between these fragmenst. Fragment A calls a http request, observes the data and if the condition is true, it navigates to fragment B.
Now if I navigate back to fragment A, it observes that data again and navigates to fragment B. In other word, every time i try to go back to A, becasue the old data is still there, it shoots me back to the B.
I tried using the by viewModel injection but the same thing happed.
I tried observing inside onCreate() but it doesn't work because the viewLifeCyclerOwber is still null.
class InitialUserDataFragment : Fragment(R.layout.fragment_initial_user_data) {
private val viewModel by sharedViewModel<KYCViewModel>()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
init()
}
private fun init() {
viewModel.localInquiryResponse.observe(viewLifecycleOwner) { response ->
if (response.isNotInProgress()) {
btnAccept.enable()
hideLoading()
}
handleResponse(response) {
if (it?.processStatus == null)
next(this)
else
gotToResult()
}
}
}
To Reproduce
Call http request in fragment A then navigate to fragment B
Try to navigate back
Fragment A observes the old data and navigates to B without even calling the http request.
Expected behavior
Fragment A does not observe old data again
Koin project used and used version (please complete the following information):
org.koin:koin-android:2.1.5
org.koin:koin-android-scope:2.1.5
org.koin:koin-android-viewmodel:2.1.5
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Describe the bug I'm not sure if this is a koin bug or LiveData bug or even a bug in general! I'm using Jetpack Navigation with one activity and bunch of framents and a view model which is shared between these fragmenst. Fragment A calls a http request, observes the data and if the condition is true, it navigates to fragment B. Now if I navigate back to fragment A, it observes that data again and navigates to fragment B. In other word, every time i try to go back to A, becasue the old data is still there, it shoots me back to the B. I tried using the
by viewModel
injection but the same thing happed. I tried observing insideonCreate()
but it doesn't work because theviewLifeCyclerOwber
is still null.To Reproduce
Expected behavior Fragment A does not observe old data again
Koin project used and used version (please complete the following information): org.koin:koin-android:2.1.5 org.koin:koin-android-scope:2.1.5 org.koin:koin-android-viewmodel:2.1.5