问题描述
我在我的项目中使用了 commit 方法,该方法使用片段构建它.
I was using the commit method in my project that built it with fragments.
无论如何,有时我会收到 IllegalStateException: Can not perform this action after onSaveInstanceState
错误,我找不到任何好的解决方案,但只有这个方法 commitAllowingStateLoss()
.我将提交函数更改为 commitAllowingStateLoss()
但没有使用它很长时间来测试所以这个函数可以帮助我吗?主要问题是,commit()
和 commitAllowingStateLoss()
之间有什么区别?
Anyway, sometimes I was getting IllegalStateException: Can not perform this action after onSaveInstanceState
error and I couldn't find any good solution about it but just this method commitAllowingStateLoss()
. I changed commit function to commitAllowingStateLoss()
but didn't use it long time to test so may this function help me? And the main question, what is the difference between commit()
and commitAllowingStateLoss()
?
推荐答案
commit()
和 commitAllowingStateLoss()
之间只有一个区别:后者没有如果发生状态丢失,则抛出异常.除此之外,它们具有相同的行为.
There is only one difference between commit()
and commitAllowingStateLoss()
: the latter doesn't throw an exception if state loss occurs. Other than that, they have identical behavior.
请参阅我的博文有关此主题的更多信息.
See my blog post about this topic for more information.
这篇关于Fragments 中的 commit() 和 commitAllowingStateLoss() 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!