views:

162

answers:

1

Hi,

This question actually has two parts.

The first part:

I've been developing my first app for a couple of weeks now. I have 5 screens and everything seems well. However, I'm considering changing the app's navigation to a TabView.

I haven't delved much into it, but I'm hoping someone can save me a little bit of time. It seems that people don't generally place Activities inside each tab. They simply point the tab content to a View. This is where my major setbacks are. 1) I already have Activity classes full of code and 2) I can't quickly guess how the structure of an app using TabView looks. For example, where do I put the handler code for clicking a button on a View? Does it all just get dumped into the TabView Activity somehow?

What I would like is if you could please give me a quick synopsis of what I'm looking at doing, answers to any questions you think I may have, and point me toward some resources for creating TabView applications. A quick Google search really just shows me how to create a TabView Activity and add a couple tabs to it. The code doesn't go any deeper. For example, say I have a layout xml to show in one of my tab's content pane, where does the code go for clicking a button I have in that layout?

The second part:

I've added a TabActivity to wrap the Activities I currently have in. At the moment I have Activities populating the content of my tabs (though ultimately I'd like to do this in the most efficient fashion, which doesn't seem to be having Activities be tab content). I've noticed something rather annoying. My MAIN Activity is an Activity I wrote for my user to log in to their account. After logging in, they are taken to my Tab Activity. Here is what happens:

When I am on my Tab Activity and I "minimize" the app by clicking the Home button and then launch it again, I don't get taken back to the Tab Activity. I get taken to my log in Activity. Why? I don't have the launchMode of my Tab Activity set to singleInstance... or is it singleInstance by default? How can I make the app re-launch showing the Tab Activity (ideally by setting some parameter, assuming I'm doing something wrong, and not having to save this data off somewhere and reading it and programmatically telling it what to go to)?

Thank you for all your time and help

A: 

I don't have a comment on the advisability avoiding the use of sub-activities in TabActivity. As for handlers -- if you aren't going to embed views instead of activities, then all the android:onclick type handler settings in your layout XML will call methods on the TabActivity. This is because they go to methods on the views' Context, which is the generally the nearest containing Activity. If you want to split your code up further without using Activities, I believe you'll have to use findViewById calls on the tab content views after you've set them up, and bind the handlers manually from there in your code.

Walter Mundt
That was my best guess, I just can't find any decent examples. Do you know of any that you could link me to? And am I essentially looking at one huuuuge TabActivity file? I plan on having around 10-or-so screens when I'm finished. Thanks for your help
Andrew
I don't know of any good examples, unfortunately. If you must avoid using sub-Activities, I'd advise setting up separate classes to hold the logic for each tab anyway. Construct each one by passing its tab's top View in the TabActivity's `onCreate` and have them bind themselves into all the events they need there.
Walter Mundt
I don't *require* not using sub-Activities, but if it's the most efficient way to implement a TabActivity, that is what I would like to do. It does bring some concerns, though. For example, say there's a button on View A that launches View B. Can I have View B show inside that same tab? When View A eventually populates the screen again, won't have to reload all data? In a few places I also use startActivityForResult. Without using Activities, this puts me in a tough spot, yes?
Andrew