保存子片段状态

时间:2018-08-21 05:20:05

标签: android android-fragments kotlin

我正在使用3个不同的片段。首先在一个片段(片段1)中,我立即在onCreateView中调用一个子片段(child)。然后在这个子片段中,当我单击按钮时,我将调用另一个不同的片段(片段2)。我将这两个片段(子片段2)添加到BackStack。

但是,这是我的问题,当我从片段2返回时,片段1调用了saveInstance = null,并且失去了子片段的状态。我的愿望是保持调用子片段2时子片段的状态。

这是我的2个片段通话:

\\ Fragment 1 to Child
override fun onCreateView(savedInstanceState: Bundle?) {
    super.onCreateView(savedInstanceState)

    showChild(screen = Screen.WORKSPACE_HOME.create(), container = R.id.Frame_layout, transition = Transition.RIGHT, addToBackStack = true, isScreen = true)}

\\ Child to Fragment 2
override fun onItemClick(v: View, position: Int) {
    val photo = items[position]
    toolbarActivity?.show(screen = Screen.IMAGE_DETAILS_WORKSPACE.create().withArguments(ITEM to photo), container = R.id.container, transition = Transition.RIGHT, addToBackStack = true)
}

0 个答案:

没有答案
相关问题