Alex Rivera | Logout

Android - Tabs, MapView, activities within tabs

Asked 2009-10-19T18:35:55.543
11

We're in the process of writing an app that has 4 tabs: Map, People, Places, Events. The People, Places, and Events in the App show up as Icons on the map. By default the People, Places, and Events tabs each show a listview, custom rendered, displaying all the People, Places, and Events respectively.

alt text http://web6.twitpic.com/img/37202700-f92052dc474b74e1760edda1c47f6940.4adcb134-scaled.png

Now, right now each of the tabs has as its content an Intent set to launch the corresponding activity. For instance, there is a MapTabActivity that extends MapActivity, a ShowPeopleListActivity that shows the people, and so on and so forth.

I see a lot of StackOverflow questions/answers saying that due to various limitations in the way the TabHost is setup, it's best NOT to use activities as the content of tabs. For instance, it's impossible to launch a new activity and have it take the place of the existing activity within a tab, whereas it's possible to switch out a View with a different view.

Now, I'm at a crossroads. We've (for better or worse) devoted a fair amount of time trying to get this app to work the way it's currently structured, with the Activities as the content of the tabs. When an icon corresponding to a Person, Place, or Event is clicked, it fires off a VIEW Intent on a URI corresponding to that object; this is picked up by an Activity that th

Edit
Report

2 Answers

8

I see a lot of StackOverflow questions/answers saying that due to various limitations in the way the TabHost is setup, it's best NOT to use activities as the content of tabs.

As self-appointed President of the Anti-Activity-Tab Alliance (AATA), that's certainly my position.

When an icon corresponding to a Person, Place, or Event is clicked, it fires off a VIEW Intent on a URI corresponding to that object; this is picked up by an Activity that then shows the object.

Note that this has nothing to do with having activities as the contents of tabs.

We can launch a new activity to show the map again, but now we have the map activity as the content of the tab, plus the show activity, plus the new map activity in the activity stack; given how resource intensive the map activity is, I'm guessing this is not the ideal way to go.

I'd avoid it if possible.

I'm worried that if we switch to the View based way of doing things, we'll have to do a LOT of housekeeping to intercept all the back events, try to switch out the views, etc., etc., as well as strongly coupling our program in a way we don't want.

This doesn't follow at all from what you wrote previously. Your "back events" will not change one iota between using Views as the contents of tabs and using Activities as the contents of tabs. Furthermore, this has nothing whatsoever to do with the "loose coupling" pattern you describe -- clicking on an icon in a list in a view in a tab is no different than clicking on an icon in a list in a view in an activity in a tab.

Just have your Show activity tell your, um, main activity to show a particular location, then the Show activity can finish(). The simplest way to do that without introducing a hard JVM coupling between the activities is to broadc

answered 2009-10-19T19:04:15.520
1

For instance, it's impossible to launch a new activity and have it take the place of the existing activity within a tab, whereas it's possible to switch out a View with a different view.

I don't think it is impossible. I experimented with this idea and wrote a blog article explaining what I did. I include a sample code project at the end of the article that demonstrates some of the interesting things I learned.

answered 2010-11-11T19:15:44.527

Your Answer