Using a tabbar, either at the top or bottom of an interface, is a typical design pattern used in apps to navigate between segments. This is used by the Android Twitter client for example. The typical way to implement this is by using TabWidget, TabActivity, TabHost and friends. Each tab is populated with whatever activity you want and all is well.
There is a problem with this approach however. If you start a new activity the tabs (area A, B, C) all disappear and this is not always what you want. Sometimes what you want is to keep the tabbar around and have an individual backstack for each of the tabs.
I’ve published an example on github that shows how you can get the best of both worlds. It explains how to keep an individual backstack for each tab, but also how to start activities that break out of the tabs as is the traditional way on Android. The Back button still works and you can also programmatically navigate back. The behavior of back is changed to respect the backstack of each individual tab.
If you want to try it out yourself I’ve compiled an Android package for you. Navigate to http://bit.ly/stacksintabs with your Android device and install the .apk to check it out.
The design is very simple. I still use TabWidget, TabHost and TabActivity (layout here) – but instead using normal activities for each tab, I subclass FragmentActivity – and build a stack of Fragments inside each tab. The gist of the code is in the addFragment(…) function
To launch a new fragment inside a tab (area D), see the launchNewFragment() function, and to see how you break out of the tabs and launch a new activity (area E) see the function launchNewActivity(…)
The fragments and activity I use are just examples, the point is that you replace ExampleActivity and ExampleFragment with you own classes.
My initial approach at solving this problem was using Fragments exclusively, but since nested Fragments are not supported on Android I gave up.
I hope this helps some of you – it’s all available under a BSD license. The example requires API level 7 and uses the Android Support library v4. Comments and contributions are welcome. Btw: I’m also working on a comparison between QML and Android XML where I compare pros and cons, so stay tuned for more








Yesterday I was presenting (covered here by
Sveinung had a really interesting talk about the different apps that apps.no had launched and how they had fared in the market. He was very frank and open about everything and I really enjoyed the talk. Our business idea is basically same as them, make own apps + consult and make apps for others, so it was really good to hear from someone that was already doing this, and succeeding. Here are the numbers:
Peter from Rovio talked about their insane success with the Angry Birds game. It’s been the top selling game for the iPhone for over 5 months, thats more than anyone else – ever. They have sold, at least, 7 million copies of it on the Apple App Store for the iPhone only, more if you add iPad. They launched in December 2009, and since then have had a crazy ride.
The last talk I attended was about HTML5 apps. Nikolai had a very enthusiastic talk about HTML5 apps, and how that was not a utopian dream, but actually a reality already. I think his talk clearly showed it is not quite there yet. The fact that for the iPhone, to use bluetooth support in an HTML5 app, you have to jailbrake it and write a platform spesific extension for PhoneGap speaks for itself.