问题:
我以编程方式将一个片段添加到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)
感谢您的时间!!:-)
| 归档时间: |
|
| 查看次数: |
2568 次 |
| 最近记录: |