views:

211

answers:

2

So, I've been banging my head looking for a good solution for a few days and am stuck.

I have a search screen (Activity) in a tab, and after the user enters a value and clicks "search" I would like the results to come back in that same tab, and then if an item from the results is selected, to show more detailed results, in that same tab. I have it all working now in separate activities, and even the first step working in a tab, but as soon as I call the activity to process he search results... i.e.

startActivity(i);

for the results Activity, the results displayed are not in the tab!

I am having a very difficult time getting this flow to work all under a tab. Any thoughts on how to make this happen?

I keep hearing that Android views should be used instead of activities, but am I then to assume that all the logic I have right now for 3 activity needs to go inside 1 activity and then I need to handle setting the content and state for each of these cases? Plus, won't the history stack not work as pressing the back button will take the user out of the application, instead of taking them from say the search result to the search screen, or the details to the search results, etc. This seems like a mess.

Can anyone show a more complex example of tabs or how one might have a simple search, result and detail workflow staying in a tab?

I have seen a few questions on this concept of keeping activities "within a tab", but no good resolution. Please help.

A: 

I think that you're going to have to keep everything inside one Activity. You'd need to capture the back button press and change change the state of your app accordingly. If they're in different Activities, you wouldn't truly be staying within your tab, or even your screen, but re-creating them at each step.

Staying inside an Activity will be more efficient, but possibly a bit more work on your part.

BenTobin
Thanks Ben. I'm a little let down by Android. I have thought about the alternative you hint at, by "recreating" the tabs for each of the screens. I agree it might be less efficient, since a new Activity would be needed, but all of the history stuff would just work out of the box. I'm hoping for some magic bullet :) But alas, maybe it doesn't exist.
Justin
I think the problem is that you're asking the back button to do more than it was intended to do. It was intended to take you back through a stack of distinct screens. Somewhat like a close button, or a back button on a browser. As a user, I tend to find that tabs aren't a great layout choice for android. Instead, I'd probably go with buttons that open distinct screens. Then separate actions would make sense, and the back button would do what you want.
BenTobin
I completely agree with BenTobin. Tabs are presentation elements, not navigational ones. That's particularly true in Android, though seems to be a general rule of thumb elsewhere as well.
CommonsWare
This interesting. I've been sitting here about 10 minutes thinking about your problem. You need to ask yourself WHY you think you need to do this? What problem are you trying to solve? If improving usability is your goal, then changing the behavior of the back button should be avoided.What is your goal with the tabs?
Wayne Young
There actually are a number of tabs this application will have, "Search" is just one of them. The point of the tabs is to compartmentalize the functionality. If someone wants to say, search for a product, they should be able to use the "Search" tab and do those activities. To find the nearest store location, there is another tab for "Locations". "Specials" is another tab to navigate through the specials. It's really no different than having tabs in a web browser where it keeps the last state. I guess I don't understand what is so weird about asking for this functionality.
Justin
Thank you everyone for taking the time to look at my problem. So, it seems like maybe this is where I'm having the disconnect - Tabs in Android aren't at all like tabs in a browser and in fact, aren't at all like tabs on other mobile platforms. They are not meant to hold state and be a distinct stack of activities. I guess I could maybe provide this functionality of hopping from "search", "locations" and "specials" with a menu button, but I kind of wanted to keep it easy to find and hop between views for the user.
Justin
Does anyone know if ActivityGroup might do what I would like to do? I posted a thread on the Google Group and am interested in any thoughts or ideas on this. Looking to basically have tabs behave like a web browser with tabs would with the back button acting on the history stack for that tab.http://groups.google.com/group/android-developers/browse_thread/thread/6b48f905dede3034
Justin
A: 

Justin, I'm facing the same problem as you. Please post back on this thread in case you get a resolution :)

Priyanka
I didn't get a resolution. :( I basically ended up living with the fact the TabHost is geared towards being more of a launch point, rather than tabs like a browser would be (i.e. each tab has it's own history stack, etc). So, once you execute your search, you are taken out of the tab and to a full screen activity. It was too much hassle and conditions to deal with the history and overriding of functionality. Would like it if they did make a true tabbed view in the future, or at least an easier way to have this functionality.
Justin