getViewLifecycleOwner() in DialogFragment leads to crash

This happens because of how the DialogFragment is created. If you use onCreateDialog() than a slightly different lifecycle is used for this type of Fragment. The onCreateView() will not be used, thus the viewLifecycleOwner for this Fragment won’t be initialized. As a workaround for this, you can use the Fragment instance as the owner for … Read more

How to correctly use Android View Binding in DialogFragment?

Use inflate(LayoutInflater.from(context)) instead. And use binding.root to set the builder view. Also, as Google suggests, it’s best practice to set the binding instance to null at onDestroyView() when using fragments: https://developer.android.com/topic/libraries/view-binding#fragments Example: class ExampleDialog : DialogFragment() { private var _binding: DialogExampleBinding? = null // This property is only valid between onCreateDialog and // onDestroyView. private … Read more

Change DialogFragment enter/exit transition at just before dismissing

You can do it inside your DialogFragment, without changing getDialog().getWindow() .getAttributes().windowAnimations You should animate “decor view” in onStart and onClick. This is the code snipped : Create Dialog first @Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(getActivity()) .setTitle(“Hello from animated dialog :)”) .setNegativeButton(“Cancel”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //we … Read more

BottomSheetDialogFragment – listen to dismissed by user event

Although all similar questions on SO suggest using onDismiss I think following is the correct solution: @Override public void onCancel(DialogInterface dialog) { super.onCancel(dialog); Toast.makeText(MainApp.get(), “CANCEL”, Toast.LENGTH_SHORT).show(); } This fires if: * the user presses back * the user presses outside of the dialog This fires NOT: * on screen rotation and activity recreation Solution Combine … Read more

DialogFragment advantages over AlertDialog [duplicate]

This is easy. DialogFragment is a fragment. So what can a fragment provide you while other objects can’t? It’s the lifecycle callbacks. So with DialogFragment, it can be very powerful and makes your code much cleaner. Have you ever seen window leaks if you didn’t close a dialog when its Activity was getting destroyed? So … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)