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