Closed midery closed 3 years ago
I couldn't press Back quickly enough, but it is easily reproducible programmatically, by calling FragmentManager.popBackStack()
immediately after commit()
, or from second fragment's onCreate()
.
Also reproduced this error when switching fragments programmatically, is there any way to destroy binding without using a handler?
Also reproduced this error when switching fragments programmatically, is there any way to destroy binding without using a handler?
Yes, you can keep reference to the delegate instance and call clear()
Need to check the bug with AndroidX Fragment 1.3.0. @midery , please do this and write about results
Need to check the bug with AndroidX Fragment 1.3.0. @midery , please do this and write about results
Checked this issue in AndroidX Fragment 1.3.0. Surprisingly, it isn't reproducing anymore.
It happens because the Fragment.onDestroyView call is now "postponed" and cancellable in new FragmentManager implementation.
Fragment.destroyFragmentView now is bound to a FragmentTransition, which is used to show fragment's removal. If the transition is not yet completed - Fragment's view won't be destroyed.
Thus, if we will try to press back after the new fragment is added and current fragment is being replaced, it will happen before transition's completion, and the viewBindings would not be cleared.
So, the logs now are showing something like this:
TL;DR: Update the AndroidX Fragment artifact to version 1.3.0+ and this issue will be fixed.
viewBindings would not be cleared
Sorry, but this is exactly the issue. I see no difference between Fragment 1.2.5 & 1.3.0 in this respect.
Here is a sample project to reproduce. After forward-back navigation the text on screen is wrong, because FirstFragment
's binding
still points to old view during onViewCreated
.
viewBindings would not be cleared
Sorry, but this is exactly the issue. I see no difference between Fragment 1.2.5 & 1.3.0 in this respect. Here is a sample project to reproduce. After forward-back navigation the text on screen is wrong, because
FirstFragment
'sbinding
still points to old view duringonViewCreated
.
Please open separate issue with your bug
Hello! Thanks for the great library and simple approach for viewBinding initialization. I've discovered really annoying bug: if we will use fragment view bindings, try to replace current fragment with new fragment, and then quickly press back - our current fragment will not show all initialization data, which we will provide in it in
onCreateView
call.This happens because we're calling
handler.post { viewBinding = null }
inClearOnDestroyLifecycleObserver.onDestroy
. method. Thus, if we happen to open next screen, and exit from it really fast, the viewBinding, that is accessed in onCreateView method will be this undestroyed binding.Method call list will be such: