architecture-components-samples icon indicating copy to clipboard operation
architecture-components-samples copied to clipboard

ViewBinding in AppCompatDialogFragment

Open enriquebautista opened this issue 4 years ago • 2 comments
trafficstars

From Official docs: Fragments outlive their views. Make sure you clean up any references to the binding class instance in the fragment's onDestroyView() method.

My question is the following:

` public class SomeDialogFragment extends AppCompatDialogFragment {

private DialogSomeBinding binding;

@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { binding = DialogSomeBinding.inflate(LayoutInflater.from(requireContext())); return new MaterialDialog.Builder(requireContext()) .customView(binding.getRoot(), false) .build(); }

// This part is necessary even if you don't use onCreateView? @Override public void onDestroyView() { binding = null; super.onDestroyView(); }

} `

enriquebautista avatar Dec 19 '20 02:12 enriquebautista

Yes, Of course you need to clean the memory ( from variable that reference the binding). Reason: Because you instantiate the variable binding, by fragment being destroyed you need to free it ( assign it null ).

amindadgar avatar Dec 22 '20 12:12 amindadgar

can i work on this issu ?

this is my first contribution

Rishavgupta12345 avatar Sep 09 '21 07:09 Rishavgupta12345