失败节能状态 - 目标不是在片段管理器(setTargetFragment) [英] Failure saving state - target not in fragment manager (setTargetFragment)

查看:391
本文介绍了失败节能状态 - 目标不是在片段管理器(setTargetFragment)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一只猴子崩溃,由此

I've got a monkey crash whereby

java.lang.IllegalStateException: Failure saving state: FragmentB has target not in fragment manager: FragmentA
at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1561)
at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:475)
at com.acme.ParentActivity.onSaveInstanceState(Unknown Source)

基本上碎裂负荷高达FragmentB和 setTargetFragment 被称为设置FragmentB的目的片段。

Basically FragmentA loads up FragmentB and setTargetFragment is called to set FragmentB's target fragment.

FragmentB然后只需调用 getTargetFragment 的onCreate 方法和挂到目标需要的时候进行。

FragmentB then simply calls getTargetFragmentin its onCreate method and hangs on to the target for when needed.

现在我什么也没做任何的的onSaveInstanceState 与目标片段调用设置方面,它空,做任何 saveFragmentInstanceState <的/ code>, putFragment 等电话。现在的问题是我应该做的事情呢?

Now I'm not doing anything in any of the onSaveInstanceState calls with the target fragment in terms of setting it null, making any saveFragmentInstanceState, putFragment etc. calls. The question is should I be doing something with it?

在此先感谢,

彼得。

**编辑1 ** 我使用的是旧版本的支持库,并有一种感觉,这可能是固定在最新的版本中,将测试进一步提供了进一步的更新,如果是这样的话。然而,仍然有兴趣知道我是否应该做的目的片段,我不是现在做任何事情。

** Edit 1 ** I am using an old version of the support library and have a feeling that this may be fixed in the latest version, will test further and provide a further update if that is the case. However, still interested to know whether I should be doing anything with the target fragment that I'm not currently doing.

**编辑1 **修正了支持库的版本8(没有尝试过其他人)。

** Edit 1 ** Fixed with version 8 of the support library (haven't tried others).

推荐答案

下面是一个解决方法:

把这个引起该问题的片段:

put this in the fragment that causes the problems:

@Override
public void onSaveInstanceState(final Bundle outState) {
    setTargetFragment(null, -1);
            ...

和记得,当你需要它把它设置为真实目的片段。

and remember to set it to the real target fragment when you need it.

这篇关于失败节能状态 - 目标不是在片段管理器(setTargetFragment)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆