Hi there! I'm having an issue after we moved to n...
# navigation-architecture-component
j
Hi there! I'm having an issue after we moved to navigation components. We are doing a lot of stuff in the
onCreateView
, that needs to be refactored, but for now we are keeping a reference to the view:
Copy code
private lateinit var binding: FragmentAbcBinding
and doing the following in that method:
Copy code
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?