1

I can't seem to find a proper way to move on from ActivityGroup. I've seen Separate Back Stack for each tab in Android using Fragments

Take the following:

  • An application with 4 tabs
  • Each tab needs to have it's own back stack (similar to iOS behaviour, yes)
  • The application may be tuned for tablets, so the back stack needs to hold Activities

Once you need to develop for tablets, the Activities will contain multiple fragments. Having a stack of Fragments won't work because Fragments can't be nested, so the stack has to contain Activities.

I can't seem to find a way around this other than to continue to use ActivityGroup.

Thanks!

EDIT 1: A concrete example.

Handheld:

 TAB 1 -> Activity 1A (Fragment 1A) 
       -> Activity 1B (Fragment 1B)  
       -> Activity 1C (Fragment 1C)

Tablet:

 TAB 1 -> Activity 1A (Fragment 1A and 1B)
       -> Activity 1C (Fragment 1C)

@beyerss I don't think I can rely on FragmentTransactions consistently. I could add multiple fragments in a Transaction as you mentioned, but the Activity layout may not be consistent. Hence I'm still seeing the need for ActivityGroups.

Community
  • 1
  • 1
mmilo
  • 806
  • 11
  • 18

1 Answers1

1

Is there a reason you can't use a FragmentTransaction which can be added to the back stack? If you have three fragments on a screen and they all change at the same time this would require three FragmentTransactions but the fragments would not be nested so it should work.

In order to get each tab to have it's own back stack you might need to be smart about managing it yourself for each tab. i.e. use an array of each FragmentTransaction that is put on the back stack and if the user switches tabs remove all of the FragmentTransactions that were stored (but still keep track of them) then when the user returns to the tab add them back on the back stack in the same order.

beyerss
  • 1,302
  • 3
  • 21
  • 38
  • Didn't really figure a best way to do this. However, I would have to roll my own "custom back stack" and design a set of layouts with organized fragments. Marking this as the best solution. – mmilo Aug 08 '12 at 03:51