android / architecture-components-samples

Samples for Android Architecture Components.
https://d.android.com/arch
Apache License 2.0
23.44k stars 8.28k forks source link

ViewBinding in AppCompatDialogFragment #937

Open enriquebautista opened 3 years ago

enriquebautista commented 3 years ago

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(); }

} `

amindadgar commented 3 years ago

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 ).

Rishavgupta12345 commented 3 years ago

can i work on this issu ?

this is my first contribution