我正在开发一个 android 应用程序,我想将我的片段保存在矢量片段中。当我在 onSaveIstanceState 中使用 putFragment 时,系统会抛出 IllegalStateException
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Salviamo lo stato
//salvo all fragment
for(int i=0;i<fragments.size();i++)
getSupportFragmentManager().putFragment(outState, Integer.toString(i), fragments.get(i));
}
这是日志猫:
09-13 10:38:10.230: E/AndroidRuntime(24089): java.lang.IllegalStateException: Fragment GenericPageFragment{417716e0} is not currently in the FragmentManager
09-13 10:38:10.230: E/AndroidRuntime(24089): at android.support.v4.app.FragmentManagerImpl.putFragment(FragmentManager.java:516)
09-13 10:38:10.230: E/AndroidRuntime(24089): at it.intects.dashboard.droid.BaseActivity.onSaveInstanceState(BaseActivity.java:180)
09-13 10:38:10.230: E/AndroidRuntime(24089): at android.app.Activity.performSaveInstanceState(Activity.java:1113)
09-13 10:38:10.230: E/AndroidRuntime(24089): at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1188)
为什么 ?我该如何解决这个错误?