On Showing Dialog I Get "Can Not Perform This Action After Onsaveinstancestate"

Showing a DialogFragment throws Can not perform this action after onSaveInstanceState error

Since dialogfragment does not have option to commitAllowingStateLoss, the simplest solution I used was to set a flag when onSaveInstance is called and reset it on onCreate and onRestoreInstance. Then before making a fragment transaction, check the flag to be sure its false. btw, this usually occurs in a asynchronous callback. The activity is already gone beyond onSaveInstance by the time background work has completed and callback has triggered.

Showing dialog fragment throws can not perform this action after onSaveInstanceState exception

As I discovered the problem was caused by Android issue, I had the following workaround solution: just override show() method of the dialog fragment as it is below:

 @Override
public void show(@NonNull FragmentManager manager, @Nullable String tag) {
FragmentTransaction ft = manager.beginTransaction();
ft.add(this, tag);
ft.commitAllowingStateLoss();
}


Related Topics



Leave a reply



Submit