Fragments中commit()和commitAllowingStateLoss()之间有什么区别 [英] What is the difference between commit() and commitAllowingStateLoss() in Fragments

查看:104
本文介绍了Fragments中commit()和commitAllowingStateLoss()之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was using the commit method in my project that built it with fragments.

不管怎样,有时我得到 IllegalStateException异常:以后的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()之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆