1

Transition: Fragment A > Fragment B

Fragment A goes through onDestroyView() and does NOT go through any other tear down methods.

Transition: Fragment B is popped and Fragment A is restored

Fragment A goes through onAttach() and onCreate(). Why is this the case? Shouldn't Fragment A only have to recreate its view?

How fragments are being replaced (in Kotlin):

private fun replaceFragment(fragment: Fragment, @IdRes frameId: Int, fragmentTag: String) {
    val transaction: FragmentTransaction = supportFragmentManager.beginTransaction()
    transaction.replace(frameId, fragment, fragmentTag)
    transaction.addToBackStack(fragmentTag)
    transaction.commit()
}

Popping the backstack this way:

supportFragmentManager.popBackStack()

user2892437
  • 1,111
  • 1
  • 14
  • 22

1 Answers1

0

The FragmentTransaction.replace() function make this. You need to instantiate your fragment, and use a solution, like ViewPager, to navigate in your fragments. The code in Java or Kotlin make the same thing. I just reply a question similar with your. Try look this: Change fragments without recreate them

Augusto
  • 3,825
  • 9
  • 45
  • 93