我有一个包含几个片段的活动,这些片段是动态添加和删除的。我注意到每次添加一个片段时fragmentManager.beginTransaction().add(containerViewId, fragment, tag).commit()
,片段的方法中收到的 BundleonCreateView(LayoutInflater, ViewGroup, Bundle)
是null
,并且在调用时fragmentManager.beginTrasaction().remove(fragment).commit()
,没有调用 frament 的方法 `onSaveInstanceState(Bunlde)。
那么有没有办法在使用片段管理器添加/删除片段时让片段保存/恢复其状态?
如果片段被保留,那么Bundle
inonCreateView
总是null
。