没有调用onSaveInstanceState():为什么?

PHF*_*PHF 7 android

问题:

我以编程方式将一个片段添加到LinearLayout.它出现在我的活动中,很棒.我转动设备 - >配置更改:一切都被销毁以重新创建.但是,在调用onDestroy()之前,应该调用onSaveInstanceState().这是父活动的情况,但不是我添加的片段.为什么?

码:

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/parent_LL"
android:stuff="myStuff"
>

<LinearLayout
    android:id="@id/categories_activity_LL1"
    android:stuff="myStuff" />

<LinearLayout
    android:id="@id/categories_activity_LL2"
    android:stuff="myStuff" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我将片段添加到父活动的UI中:

ft.add(container1, categories, CatFragIds.CATEGORIES.toString()).commit();
Run Code Online (Sandbox Code Playgroud)

我重写我的片段的onSaveInstanceState():

@Override
public void onSaveInstanceState(Bundle outState) {

    // Récupère extensible
    boolean extensible = ((CategoryAppsListView) this.getListView())
    .isExtensible();

    mState.setExtensible(extensible);

    // Transmet l'état de CategoriesListElems
    FragmentManager fm = getFragmentManager();

    @SuppressWarnings("unchecked")
    FragRetainObject<CategoriesListElemsState> retainedState = 
    (FragRetainObject<CategoriesListElemsState>)
    fm.findFragmentByTag(CATEGORIESLISTELEMS_STATE+"_"+this.getTag());

    if( retainedState == null) {
        retainedState = 
        FragRetainObject.<CategoriesListElemsState>newInstance(mState);

        fm.beginTransaction()
        .add(retainedState, CATEGORIESLISTELEMS_STATE+"_"+this.getTag()).commit();
    }
    else retainedState.setRetainObj(mState);

    super.onSaveInstanceState(outState);
}
Run Code Online (Sandbox Code Playgroud)

感谢您的时间!!:-)

Din*_*ati -2

您需要将配置更改作为方向和键盘放入 AndroidManifest.xml 中