android使用DialogFragment出现java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState的解决方法

调用 dialog.show(getSupportFragmentManager(), "tag");时出现了java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState的错误。

报错的原因:dialog.show()方法的内部使用了commit()方法提交事务,某些时候因为状态异常而报错。解决方法就是使用commitAllowingStateLoss()方法,具体如下所示:

解决方法:不调用dialog.show()方法,而是调用getSupportFragmentManager().beginTransaction().add(dialog, "tag").commitAllowingStateLoss();
原文地址:https://www.cnblogs.com/yongfengnice/p/10403000.html