Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Fragment not paused when showing DialogFragment

In one part of my application, I show the user a ListView. When the user presses an item in the list, a DialogFragment is shown.

@Override
public void onClick() {
    android.support.v4.app.FragmentTransaction ft = getFragment().getFragmentManager().beginTransaction();
    ft.addToBackStack(null);
    SingleSettingDialogFragment dialog = SingleSettingDialogFragment.newInstance(...);
    dialog.show(ft, "Single");
}

The DialogFragment have the following structure:

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceSate);
    AlertDialog dialog =  new AlertDialog.Builder(...)
        ...
        .create();
    ...
    return dialog;
}

When the user exits the DialogFragment, I expect the onResume() method of the calling fragment to be called, but it is not.

So what's so special about DialogFragments? Why aren't the calling Fragment paused when the Dialog is shown? And how can it be achieved?

I haven't found any reference to this behaviour in the Docs, so references is a plus.

like image 958
Joakim Avatar asked Sep 17 '15 10:09

Joakim


1 Answers

This may help you: link

In fact a FragmentDialog is not an activity on itself but it is part of the same activity which contains the calling fragment. It means that the fragment is not paused when dialogFragment is shown.

Citing the source I gave you, a fragment is paused when: Another activity is in the foreground and has focus, but the activity in which this fragment lives is still visible (the foreground activity is partially transparent or doesn't cover the entire screen).

Hope that helps

like image 125
gbaccetta Avatar answered Oct 05 '22 09:10

gbaccetta