androidbroadcast / ViewBindingPropertyDelegate

Make work with Android View Binding simpler
https://proandroiddev.com/make-android-view-binding-great-with-kotlin-b71dd9c87719
Apache License 2.0
1.42k stars 102 forks source link

IllegalStateException FragmentViewBindingProperty.getLifecycleOwner #105

Closed galaxi76 closed 1 year ago

galaxi76 commented 1 year ago

Fragment doesn't have view associated with it or the view has been destroyed

by.kirich1409.viewbindingdelegate.FragmentViewBindingProperty.getLifecycleOwner (FragmentViewBindings.kt:65) by.kirich1409.viewbindingdelegate.FragmentViewBindingProperty.getLifecycleOwner (FragmentViewBindings.kt:34) by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.getValue (ViewBindingProperty.kt:76) by.kirich1409.viewbindingdelegate.FragmentViewBindingProperty.getValue (FragmentViewBindings.kt:42) by.kirich1409.viewbindingdelegate.FragmentViewBindingProperty.getValue (FragmentViewBindings.kt:34) com.xxx.MainFragment.getBinding (MainFragment.kt:53) com.xxx.MainFragment.onSaveInstanceState (MainFragment.kt:216)

90% occurrence in background

kirich1409 commented 1 year ago

This is normal behaviour, because Fragment's view has been destroyed. Try to add check

if (view != null) {
   // Do something with viewBinding
}