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

报如下异常:java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState #11

Closed
HolenZhou opened this issue Sep 15, 2015 · 3 comments

Comments

@HolenZhou
Copy link

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1377)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1395)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:637)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:616)
at com.talkweb.cloudcampus.view.ActionSheet.show(ActionSheet.java:65)
at com.talkweb.cloudcampus.view.ActionSheet$Builder.show(ActionSheet.java:482)
at com.talkweb.cloudcampus.ui.common.ImageViewPagerActivity.LongPress(ImageViewPagerActivity.java:128)
at com.talkweb.cloudcampus.ui.common.ImageViewPagerActivity$ImagePagerAdapter$2.onLongClick(ImageViewPagerActivity.java:155)
at com.talkweb.cloudcampus.view.gallery.touchview.TouchImageView$1.onLongPress(TouchImageView.java:146)
at android.view.GestureDetector.dispatchLongPress(GestureDetector.java:690)
at android.view.GestureDetector.access$200(GestureDetector.java:37)
at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:266)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5372)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)

很难复现的情况,不知道是不是使用方法的问题?

@baoyongzhang
Copy link
Owner

当Activity不在前台的时候,系统可能会回收的时候会调用onSaveInstanceState,这时候再show就会出现这个异常。将show方法里面的commit改为commitAllowingStateLoss应该可以解决。

@HolenZhou
Copy link
Author

我试了将commit改为commitAllowingStateLoss,也查过原因应该是当前Activity被回收造成的,但是我无法复现这个crash,不知是不是有什么方法可以复现这个crash呢?因为有其他地方有类似的crash,如果可以复现,我就可以测试是否真正解决,我自己通过更改手机字体大小来模拟内存回收,但也没演示出bug,请大牛指点,非常感谢!

@XingmingLi
Copy link

@HolenZhou
用Handler延迟执行一个继承自DialogFragment的对话框的显示。显示前按home,就可以出现这个错。
我的解决办法(针对对话框):
`override fun show(manager: FragmentManager?, tag: String?) {
if (manager == null)
return

    if (Integer.valueOf(android.os.Build.VERSION.SDK) > Build.VERSION_CODES.JELLY_BEAN) {
        if (manager.isDestroyed)
            return
    }

    try {
        super.show(manager, tag)
    } catch (e: Exception) {
        e.printStackTrace()
    }
}`

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

3 participants