How can I receive the OnBackPressed event within a DialogFragment?
I'm creating a custom DialogFragment
causing it to call onCreateView()
and not onCreateDialog
.
Therefore I'm unable to set an OnDismissListener
or OnCancelListener
since mDialog is null.
I'm calling my DialogFragment like this:
FragmentManager fragmentManager = ((AppCompatActivity) mContext).
getSupportFragmentManager();
DialogFragmentCustom newFragment = DialogFragmentCustom.newInstance(...);
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.add(android.R.id.content, newFragment);
transaction.addToBackStack(null);
transaction.commit();
Do you have an idea how to solve my problem?