1

There are several questions on StackOverflow, but non of them incorporating DialogFragment. The usual solution is to use commitAllowingStateLoss() instead of commit(). But how do I accomplish that for DialogFragment?

The following is the code of show() method of DialogFragment. There's ft.commit() on it but I cannot change it to commitAllowingStateLoss()

public void show(FragmentManager manager, String tag) {
    mDismissed = false;
    mShownByMe = true;
    FragmentTransaction ft = manager.beginTransaction();
    ft.add(this, tag);
    ft.commit();
}

Here how I implement DialogFragment

public class ProgressFragment extends DialogFragment {
    private String message;

    public static ProgressFragment getInstance() {
        return new ProgressFragment();
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        ProgressDialog progressDialog = new ProgressDialog(getActivity());
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.setCancelable(false);
        progressDialog.setIndeterminate(true);
        progressDialog.setMessage(message);

        return progressDialog;
    }

    public void show(String message, FragmentManager manager, String tag) {
        this.message = message;
        show(manager, tag);
    }
}
Stempart
  • 11
  • 1
  • Yes, [you can change it](http://developer.android.com/reference/android/app/FragmentTransaction.html#commitAllowingStateLoss%28%29) – Ilario Sep 01 '15 at 05:33

1 Answers1

0

See On showing dialog i get "Can not perform this action after onSaveInstanceState":

public class ProgressFragment extends DialogFragment {

    @Override
    public void show(FragmentManager manager, String tag) {
        try {
            FragmentTransaction ft = manager.beginTransaction();
            ft.add(this, tag);
            ft.commit();
        } catch (IllegalStateException e) {
        }
    }
}
CoolMind
  • 26,736
  • 15
  • 188
  • 224