保存的包不包含数据

时间:2014-02-07 22:22:21

标签: android android-fragments

我有两个可序列化的对象,我想在重建片段后保留这些对象。因此我在onSaveInstanceState期间保存了它们(这里的对象不为null):

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putSerializable(RENDERER, renderer);
    outState.putSerializable(SERIES, series);
}

在片段的onCreate方法中,我尝试将它们从Bundle中取出:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        renderer = (DefaultRenderer) savedInstanceState.getSerializable(RENDERER);
        series = (CategorySeries) savedInstanceState.getSerializable(SERIES);
    }
}

问题是“renderer”和“series”在调用getSerializable后始终为null。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

您是否覆盖托管此片段的onSaveInstanceState中的FragmentActivity方法?如果您是,请确保它应调用super.onSaveInstanceState(Bundle)