我正在尝试将嵌套的子片段添加到父片段中。
一切正常,但是....
起初我的代码:
public class FragmentDatasheetWithHeader extends Fragment {
private long mRowId;
private String mSid;
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
final ScrollView scrollView = new ScrollView(getActivity());
final LinearLayout linearLayout = new LinearLayout(getActivity());
linearLayout.setId(4711);
linearLayout.setOrientation(LinearLayout.VERTICAL);
scrollView.addView(linearLayout);
createUI();
return scrollView;
}
private void createUI() {
final FragmentProductDetailHeader fragmentHeader = FragmentProductDetailHeader.newInstance(this.mRowId, FragmentProductDetailHeader.HEADERTYPE_SMALL);
final FragmentDatasheet fragmentDatasheet = FragmentDatasheet.newInstance(this.mRowId, this.mSid);
final FragmentManager fragmentManager = getChildFragmentManager();
fragmentManager.beginTransaction().add(4711, fragmentHeader, "fragmentHeader").commit();
fragmentManager.beginTransaction().add(4711, fragmentDatasheet, "fragmentDatasheet").commit();
}
}
现在我的问题:
在开发人员选项中,我激活了“不要保留活动(用户离开后立即销毁每个活动)”
当带有 FragmentDatasheetWithHeader 的活动打开并且应用程序进入后台并返回前台时,嵌套的 Fragment 会加倍。但它仅在嵌套 Fragments 的容器是 LinearLayout 时才会出现。如果容器是 FrameLayout,则嵌套的 Fragments 不会加倍。
怎么了?