androidarchitecturetabsview

Android - how to make a complex tabbed app with views


This is my first question on Stack Overflow, apologies if it is not well formed.

I am developing a relatively complex tabbed app and already had the basics set up before coming across information that ActivityGroup and TabActivity are deprecated, and the preferred model is to use views.

I have had no trouble using views, this is a question about architecture rather than syntax (which is why I haven't posted any code). Specifically, how should I go about restructuring the app to use views instead of Intent launched Activities.

The app has five tabs; two hold a single layout, no problem there. The other three tabs are running an ActivityGroup with 2-5 different Activities (i.e. a tab running an activity for settings, where clicking each view starts a new Activity dealing with that particular setting, pressing the back button returns you to the broader settings activity/view). If I were to keep each Tab as a TabActivity, it would still be fairly easy to change those internal transitions to views as opposed to separate Activities.

The main question is using ONLY views, no TabActivity/Activity group at all. The vast majority of the research I've done has been discussion about whether to use Activities or Views or about specific syntax. I haven't been able to gather a clear idea of how to MAKE the transition to views across the whole application.

  1. If I were to do so, wouldn't the entire app now be running in a single Activity - the one hosting the tabbed layout?

  2. If (1) is true, how to manage this? Despite ActivityGroup being deprecated, all of the Android documentation still seems to state that it is preferred to use separate Activities for separate aspects of functionality--which makes sense. Did the Android development team simply decide that the costs to the stack and the device made the TabActivity implementation ineffective?

  3. If the application is running in a single Activity that manages different views for each tab (and then different views WITHIN a tab when necessary), should I have one single enormous onClick method to handle all clicks from any clickable view, handling input based on which view is active? Or should I register and de-register all of my Listeners programmatically?

  4. With a single Activity, won't any click listener or any broadcast receiver be running all of the time, consuming resources even when unnecessary?

  5. With a single Activity, the back button would exit the entire app from any point in its functionality. If I am using views, won't I have to consistently override onBackPressed() and carefully manage the app behavior to force it to behave "like an Android app?"

  6. AM I THINKING ABOUT THIS COMPLETELY WRONG? I may be unintentionally attempting to recreate ActivityGroup and TabActivity functionality using views instead when I should be taking an entirely different design approach to using tabs and Views.

When the people at Google say we shouldn't use activities as tabs anymore, and Mr. Mark Murphy so emphatically agrees, I'm inclined to believe. I simply haven't been able to research a way to switch without resorting to recreating a lot of Activity functionality by hand (which would probably include a variety of dirty hacks).

Appreciation in advance for anyone willing to tackle such a vague and overwritten topic.


Solution

  • Using Fragments is the new standard for performing tabbed style ui components, I think you must have just overlooked them because they are the missing piece to all your above questions. Good luck.

    Don't forget that using the compatibility library brings Fragment support all the way back to 1.6.

    And here is an easy Google recommended tutorial on using Fragments within a TabHost.