Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
278 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...