Fragments中commit()和commitAllowingStateLoss()之间有什么区别

Mer*_*din 44 java android android-fragments

我在我的项目中使用了commit方法,它使用片段构建它.

无论如何,有时我得到IllegalStateException: Can not perform this action after onSaveInstanceState错误,我找不到任何关于它的好解决方案,但只是这种方法commitAllowingStateLoss().我改变了提交功能,commitAllowingStateLoss()但没有长时间使用它进行测试,所以这个功能可以帮助我吗?而主要的问题是,commit()和之间有什么区别commitAllowingStateLoss()

Ale*_*ood 90

commit()和之间只有一个区别commitAllowingStateLoss():后者在发生状态丢失时不会抛出异常.除此之外,他们有相同的行为.

有关更多信息,请参阅我关于此主题的博文.