ariets
ariets

Reputation: 4268

Tabs, Activities and Nested Fragments

I am starting a new application and need to have a set of tabs. Inside each tab, I need multiple screens, each with its own back stack (required by the client). Here is a quick diagram of what I mean:

Tab 1
   |
   |_Screen1a --> Screen1b --> Screen1c
Tab 2
   |
   |_Screen2a -->Screen2b
Tab 3
   |
   |_Screen3a --> Screen3b --> Screen3c --> Screen3d
...etc

Now, I have done this before using a FragmentActivity as the tab host activity. Each tab was then a FragmentActivity that housed each Fragment. By that, I mean the following:

FragmentActivity
    FragmentActivity1
       |
       |_Fragment1 --> Fragment2 --> Fragment3
    FragmentActivity2
       |
       |_Fragment4 --> Fragment5
    FragmentActivity3
       |
       |_Fragment6 --> Fragment7 --> Fragment8 --> Fragment9
    ...etc

Now, with the release of the 4.2 SDK and the new revision of the Support Library, there are nested fragments. This allows you to put a fragment inside of another fragment (I am assuming you can continue the nesting, though haven't tested it yet). I was thinking about switching to using nested fragments as I am currently using deprecated methods in my Tab host activity. Essentially, I would have the entire flow of my application implemented in fragments with a single, host activity.

Is there any downfall to this in terms of performance issues, or memory issues, etc? Or should I go with the implementation that I have done before and use the deprecated methods?

Upvotes: 4

Views: 1388

Answers (1)

ChinaMan
ChinaMan

Reputation: 39

Nested Fragments can help solve your problem, I've tried this implementation. But don't add child Activity(intent) into TabHost's TabSpec. All child Activities should be replaced with Fragments. But in my option, I don't think this implementation is good. Because navigation will be a little wired since Android has a back key. And pressing back key usually returns the user to the previous screen. But this tab thing will mess up the back navigation.

Upvotes: 1

Related Questions