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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM