片段上没有调用onSaveInstanceState

时间:2014-03-28 20:58:29

标签: android

我正在用另一个片段替换片段:

    FragmentTransaction transaction = mFragmentManager.beginTransaction();

    transaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit);
    transaction.replace(R.id.main_container, nextFragment, nextFragment.getClass().toString());
    transaction.addToBackStack(nextFragment.getClass().toString());
    transaction.commit();

然而,被替换的片段,其onSaveInstanceState未被调用。我做错了什么?

1 个答案:

答案 0 :(得分:3)

"在片段中,所有生命周期回调都直接与其父Activity相关联。因此,当其父Activity调用onSaveInstanceState时,会在Fragment上调用onSaveInstanceState。"

看看这篇文章:

FragmentActivity onSaveInstanceState not getting called