I am trying to use ViewBinding in Fragments.
First, Google said as below :
Note: Fragments outlive their views. Make sure you clean up any references to the binding class instance in the fragment's onDestroyView() method. [Use view binding in fragments]
So, I have wrote the code as below :
private var _binding: ResultProfileBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
Then, I got a concern about NPE after onDestoryView().
It is safe? Suppose you received a network response at some point between onDestoryView() and onDetact()