Joao Birk
10/06/2020, 2:39 PMonCreateView
, that needs to be refactored, but for now we are keeping a reference to the view:
private lateinit var binding: FragmentAbcBinding
and doing the following in that method:
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
if (!::binding.isInitialized) {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_abc, container, false)
} else {
val rootView = binding.root
(rootView.parent as? ViewGroup)?.removeView(rootView)
}
return binding.root
}
But for some reason, in some devices we are seeing the following crash:
*java.lang.IllegalStateException*:
at android.view.ViewGroup.addViewInner (ViewGroup.java:5958)
at android.view.ViewGroup.addView (ViewGroup.java:5777)
at androidx.fragment.app.FragmentContainerView.addView (FragmentContainerView.java:6)
Basically the binding.root
still has a view being returned when calling binding.root.getParent()
Unfortunately the stack trace doesn't tell me which fragment is throwing such exception.
We are using the https://github.com/android/architecture-components-samples/blob/master/NavigationAdvancedSample/app/src/main/java/com/example/android/navigationadvancedsample/NavigationExtensions.kt
Has anyone here faced this issue?