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

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

java - What is the difference between commit() and commitAllowingStateLoss() in Fragments

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

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...