Android:在onSaveInstanceState之后无法执行此操作

时间:2012-01-05 23:20:07

标签: android

我仍然不清楚处理碎片以及我活动中发生的其他事情。以下是堆栈跟踪:

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { (has extras) }} to activity {com.ghcssoftware.gedstar/com.ghcssoftware.gedstar.GedStar}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.app.ActivityThread.deliverResults(ActivityThread.java:2747)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:2790)
at android.app.ActivityThread.access$2000(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1035)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4028)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1299)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1310)
**at android.support.v4.app.FragmentManagerImpl.popBackStack(FragmentManager.java:471)
at com.ghcssoftware.gedstar.PersonTab$PersonTabFrag.popStack(PersonTab.java:157)**
at com.ghcssoftware.gedstar.PersonTab$PersonTabFrag.fillData(PersonTab.java:165)
at com.ghcssoftware.gedstar.ViewTab.fillData(ViewTab.java:96)
at com.ghcssoftware.gedstar.GedStar.fillData(GedStar.java:589)
at com.ghcssoftware.gedstar.GedStar.onActivityResult(GedStar.java:514)
at android.app.Activity.dispatchActivityResult(Activity.java:4541)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2743)

所以这看起来是我在这个函数中调用popBackStack,我在其中一个视图窗格中清理掉任何堆积的碎片:

    // Pop fragments from second pane
    private void popStack() {
        if (mDualPane && mBottomId >= 0) {
            mViewTab.getTabHelper().tabGetFragManager().popBackStack(mBottomId, 
                    FragmentManager.POP_BACK_STACK_INCLUSIVE);
            mBottomId = -1;
        }
    }

主要是我不确定为什么在“onSaveInstanceState之后”调用之后发生了这种情况,或者这是真正发生的事情。任何可能的解释? popBackStackImmediate会有所作为吗?

对于它的价值,我无法在我的测试中重新创建环境,所以它只会出现在报告中。

1 个答案:

答案 0 :(得分:15)

  

从查看跟踪可以看出这个问题,就是我在onActivityResult方法中调用popStack,而onActivityResult方法在onResume之前调用。我将调用移动到onResume并修复它。