Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity.onBackPressed()的时候抛出Can not perform this action after onSaveInstanceState的异常 #490

Open
diov opened this issue Jul 7, 2016 · 7 comments

Comments

@diov
Copy link

diov commented Jul 7, 2016

项目中所使用的Fragment都是v4包里的。而且调用的都是commitAllowingStateLoss()方法。

之前发现线上的用户在结束Activity的时候会在v4包的FragmentManagerImpl里面抛出Can not perform this action after onSaveInstanceState的异常。看源码的时候发现是因为mStateSaved=true导致的,所以就简单的调了一下FragmentActivity的onStateNotSaved()方法,在销毁之前讲mStateSaved设置为false

但是更新之后,发现用户仍然会报这个crash。FragmentActivity的onBackPressed()会走到Activity的onBackPressed()方法,在这个方法中最终会调用android.app.FragmentManagerImpl.checkStateLoss(),同样会抛出Can not perform this action after onSaveInstanceState的异常。而之前的onStateNotSaved()只修改了v4包里Fragment的mStateSaved的值。

想问一下有没有什么简单的方法可以避免这个异常,或者帮忙分析一下为何会抛出这个异常。目前搜索到的答案都与这种情况不同

@imknown
Copy link

imknown commented Jul 7, 2016

不知道你在干啥.. 只看到你 在不停的 阐述问题...

@diov
Copy link
Author

diov commented Jul 7, 2016

@imknown 哈哈,就是目前能查找到的答案,都是说用commitAllowingStateLoss ()可以避免这个异常,但是现在还是会出现这个问题

@imknown
Copy link

imknown commented Jul 7, 2016

生命周期 是按照你的 业务 设计的吗?

@diov
Copy link
Author

diov commented Jul 7, 2016

@imknown 生命周期就是Activity管理四个Fragment,并没有什么特别复杂的逻辑。

@chopiter
Copy link

chopiter commented Jul 7, 2016

贴下代码,简单的demo

@x1a0b0
Copy link

x1a0b0 commented Aug 22, 2016

commitAllowingStateLoss()只能避免create Fragment时的异常,不能避免destroy Fragment时的异常

@erossssssss
Copy link

onStateNotSaved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants