Javier
02/05/2020, 11:35 AMprivate var _binding: ResultProfileBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = ResultProfileBinding.inflate(inflater, container, false)
val view = binding.root
return view
}
override fun onDestroyView() {
_binding = null
}
binding cannot be null never? If for some reason I want to get the context via binding.root.context and the fragment is not attached, I can not get a NPE? @jwarekolek
02/05/2020, 11:46 AMJavier
02/05/2020, 11:47 AMarekolek
02/05/2020, 11:47 AMJavier
02/05/2020, 11:51 AM_binding!! and Kotlin type safe feature is not being affected.satyan
02/05/2020, 11:56 AM_binding is set to null onDestroyView (which make sense since the binding is suppose to contains the view)satyan
02/05/2020, 11:58 AMonDetach being after onDestroyView)
In which use case would you need to get the attached context of your fragment after onDetach ?satyan
02/05/2020, 12:00 PMJavier
02/05/2020, 12:45 PMonDestroy and the problem was resolved. Then I have doubts about if I can get the same problems I had with synthetics if I don't check if any view or view context is null with view binding