2

I have an app, which has folowing architecture:

It has FragmentActivity which contains a Fragment. This fragment contains TabHost with 4 tabs in there. Each tab has own layout. And I'm creating new fragments and bind them to these ayouts. Well, finally I have 4 fragments.

Each fragment can start some new fragments as it's child. I thought that each fragment has own backstack. But it seems like it's not. Looks like it common backstack for these fragments.

I mean if I choose first tab, and start new child fragment from there, then I select second tab, start new child fragment from there, then I back to first tab, and press back button, and it destroys child fragment from SECOND tab but not from the first tab. If I press back button one more time, then it successfully destroy child fragment from first tab.

Well, I found some kind of same problem here Separate Back Stack for each tab in Android using Fragments

Someone offers to wrap each of these 4 fragments to FragmentActivity, but I'm afraid that it will take too much time to refactor all my code. Because project is finishing soon, and I don't have much time for such massive refactoring.

Maybe someone could offer better solution for my problem?

Dmitriy

Community
  • 1
  • 1
Dmitriy
  • 830
  • 3
  • 15
  • 29

1 Answers1

2

It has FragmentActivity which contains a Fragment. This fragment contains TabHost with 4 tabs in there. Each tab has own layout. And I'm creating new fragments and bind them to these ayouts. Well, finally I have 4 fragments.

The structure should have been like this :

Activity hosting a TabHost containing 4 FragmentActivities(one for each tab). Each FragmentActivity will have its own backstack. This should give you the result you want.

If you haven't considered trying FragmentTabsPager You might wanna take a look at it and see if it suits your need. This will have a better User Experience too.

Refactoring should not take much time if you are trying to move stuff from Fragments to Activities and Vice-Versa.

Good luck.

500865
  • 6,920
  • 7
  • 44
  • 87
  • how can the TabHost host 4 FragmentActivities. In the example you've shown, each Tab FragmentActivity has a Fragment inner class, and that's the one inserted in the TabHost. I don't think they're using different backstacks, but rather the main backstack. Is this correct? – ffleandro Oct 31 '12 at 11:48