1

I am using 3 different fragments. First in a fragment (fragment 1), I immediately call a child fragment (child) in onCreateView. Then in this child fragment, when I click on a button I call another different fragment (fragment 2). I add these 2 fragments (child and fragment 2) to BackStack.

But here is my issue, when I return from fragment 2, fragment 1 is called with savedInstance = null and I loose the state I had from the child fragment. My wish is to keep the state I had from the child fragment when I call fragment 2. How can I do that please ?

Here are my 2 fragments calls :

\\ 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 Answers0