在 DialogFragment 上的 onSaveInstanceState 后无法执行此操作
Posted
技术标签:
【中文标题】在 DialogFragment 上的 onSaveInstanceState 后无法执行此操作【英文标题】:Can not perform this action after onSaveInstanceState on DialogFragment 【发布时间】:2015-11-26 04:21:12 【问题描述】:*** 上有几个问题,但没有一个包含 DialogFragment。通常的解决方案是使用commitAllowingStateLoss()
而不是commit()
。但是对于DialogFragment
,我该如何实现呢?
以下是DialogFragment
的show()
方法的代码。上面有ft.commit()
,但我无法将其更改为commitAllowingStateLoss()
public void show(FragmentManager manager, String tag)
mDismissed = false;
mShownByMe = true;
FragmentTransaction ft = manager.beginTransaction();
ft.add(this, tag);
ft.commit();
这里是我如何实现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);
【问题讨论】:
是的,you can change it 【参考方案1】:见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)
【讨论】:
以上是关于在 DialogFragment 上的 onSaveInstanceState 后无法执行此操作的主要内容,如果未能解决你的问题,请参考以下文章
如何在xamarin android的MainActivity上的dialogFragment中显示editText的文本?
休眠拦截器 - 为啥在 onSave 之后调用 onFlushDirty?