6

I am a bit confused about the rationale behind the FragmentManager's backstack.

Given that an activity has two containers for housing different fragments: the problem is that when adding fragments to the two containers by using a fragment transaction, the backstack's count will increment, regardless the container that's being used.

This doesn't really make sense to me. If this is not the promoted way for doing it in Android, then how can we manage 2 backstacks independently within the same activity (there is only one FragmentManager per activity)?
I'm probably just missing something obvious here.

html_programmer
  • 18,126
  • 18
  • 85
  • 158
  • 1
    You’re not missing anything, Fragments were a bad decision back in the day and still are today, despite what Google keeps trying to do with them. “Pieces of things that have some sort of lifecycle but are not activities”. – Martin Marconcini Oct 14 '17 at 01:59

1 Answers1

0

Fragments are modules that are attached to an Activity and shouldn't know each other fragments and the communication should be through an Activity.

Fragments are managed by a FragmentManager that are provided by an Activity and each action such as add, remove, or replace a fragment are provided through a FragmentTransaction and you will have only one backstack available per activity. So, as @hackbod said at this post:

You will just need to implement your own separate back stacks or you can manage by using FragmentTransaction.detach.

Thiago Souto
  • 761
  • 5
  • 13