I have a Fragment that’s using View Binding, so it sets its _binding
member variable in onCreateView
and nulls it out in onDestroyView
. In onViewCreated
, I observe a LiveData from the view model using viewLifecycleOwner
as the LifecycleOwner. (In reality this is split between a fragment and a base class, but I can’t see how that would explain any of this)
I can’t reproduce this in house, but crashlytics is reporting cases in the field where the LiveData’s observer is getting called back when the binding is null, making me think that somehow it’s being called after onDestroyView
has been called. Any idea how that’s possible?
UPDATE: Turns out the observer was calling postDelayed on one of the views, so the Runnable was being executed (and accessing the binding) after onDestroyView had been called.
Thanks to @Zain and @EpicPandaForce for taking a look.