On showing dialog i get “Can not perform this action after onSaveInstanceState”

前端 未结 17 1070
甜味超标
甜味超标 2020-11-29 18:37

Some users are reporting, if they use the quick action in the notification bar, they are getting a force close.

I show a quick action in the notification who calls t

17条回答
  •  庸人自扰
    2020-11-29 19:26

    This is common issue. We solved this issue by overriding show() and handling exception in DialogFragment extended class

    public class CustomDialogFragment extends DialogFragment {
    
        @Override
        public void show(FragmentManager manager, String tag) {
            try {
                FragmentTransaction ft = manager.beginTransaction();
                ft.add(this, tag);
                ft.commit();
            } catch (IllegalStateException e) {
                Log.d("ABSDIALOGFRAG", "Exception", e);
            }
        }
    }
    

    Note that applying this method will not alter the internal fields of the DialogFragment.class:

    boolean mDismissed;
    boolean mShownByMe;
    

    This may lead to unexpected results in some cases. Better use commitAllowingStateLoss() instead of commit()

提交回复
热议问题