Closed arsvechkarev closed 2 years ago
I have the same case kinda. In my case crash appears after I added logic with cleaning viewBinding delegate:
class MyFragment : Fragment(R.layout.my_fragment) {
private val bindingDelegate = viewBinding<MyFragment, MyFragmentBinding>(MyFragmentBinding::bind)
private val binding by bindingDelegate
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel.myLiveData.observe(viewLifecycleOwner) {
binding.viewToSetData // ... try to interact with view throws IllegalStateException
}
}
override fun onDestroyView() {
bindingDelegate.clear()
super.onDestroyView()
}
}
The crash isn't stable - sometimes it's reproducing, sometimes no. Library version is 1.5.3
In 1.5.6 I added functions that isn't connected to Lifecycle of Activity. You can use them viewBindingLazy()
or viewBindingWithLifecycle()
@arsvechkarev did the fix help you?
Yeah, thanks, upgrading to 1.5.6 solved the problem! Although I'm somewhat confused: was I supposed to use viewBindingWithLifecycle()
to fix my issue? Because after upgrading to 1.5.6 my code starts working without me doing anything to it
In your case viewBinding
delegate by default connected with lifecycle of Activity. If it normal for you, continue to use it
In 1.4.6, code below that uses view binding delegate with
CreateMethod.INFLATE
works as expected:In 1.5.3 this code crashes with the following exception:
I suspect that the problem is either in
isViewInitialized
method inActivityViewBindingProperty
, or in my code above. Any idea on how to fix this?P.S I created a sample project where you can successfully reproduce this issue