相关疑难解决方法(0)

儿童片段被破坏没有充分的理由

信息:我有一个2窗格布局(2个孩子Fragments)ParentFragment,当然,它在一个内部FragmentActivity.我setRetainInstance(true)ParentFragment.在方向更改时,子片段不会被销毁(onCreate()不会被调用),这是正常的(因为父节点保留其实例).

问题:在方向改变时,正确的片段破坏(onCreate()被调用).为什么地狱是正确的片段被破坏而左边的片段不是?

编辑:如果我删除setRetainInstance(true),那么左边的片段onCreate()被调用两次(lol wtf),右边的片段onCreate()被调用一次.所以这也不好......

ParentFragment的代码如下:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    this.setRetainInstance(true);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState)
{
    View view = inflater.inflate(R.layout.fragment_schedule, container, false);
    setHasOptionsMenu(true);


    if (getChildFragmentManager().findFragmentById(R.id.fragment_schedule_framelayout_left) == null || 
            !getChildFragmentManager().findFragmentById(R.id.fragment_schedule_framelayout_left).isInLayout())
    {
        if (mPresentationsListFragment == null)
            mPresentationsListFragment …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-fragmentactivity android-nested-fragment

5
推荐指数
1
解决办法
3531
查看次数