mardi 18 août 2020

What is the advantage of using following pattern as described in developer docs

I was going through developer docs for Data binding. I found the following snippet:

private 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() {
    super.onDestroyView()
    _binding = null
}

Can anyone let me know the principle and advantage of using two variables for binding which are used in same fragment?

Aucun commentaire:

Enregistrer un commentaire