Android ViewPager IllegalStateException:onSaveInstanceState 之后无法执行此操作
我正在使用兼容性库中的 ViewPager。我经常从市场报告中看到这种例外情况。
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1242)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1253)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:535)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:519)
有什么想法可能会导致它吗?
I am using a ViewPager from the compatibility library. I get this exception quite often from the market reports.
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1242)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1253)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:535)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:519)
Any ideas what might cause it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试用
commitAllowingStateLoss()
而不是commit()
。阅读文档此处。
从此处得到答案。
Try
commitAllowingStateLoss()
instead ofcommit()
. Read thedocumentation here.
Got answer from here.
您可能在错误的位置调用
FragmentTransaction.commit()
。需要在保存状态之前调用它 。You are probably calling
FragmentTransaction.commit()
in the wrong place. It needs to be called before state is saved.