0

i am using the following method in a new application i'm developing.

there is a main activity, which instantiates different classes that extends RelativeLayout, and i'm using setContentView to switch between the different modules of the application.

i wonder if this is a good approach or necesarily i have to use different activities to the several screens the app haves.

Alexander Fradiani
  • 1,001
  • 3
  • 13
  • 33

1 Answers1

0

I'd recommend using different activities, then you automatically get navigation between them via the back button. Plus, there will be subtle things that won't work right if you do it the way you're describing -- for example, Android automatically saves the focused control when you switch activities. It won't do this for your content views; you would have to save/restore focus yourself.

Alternatively, if it doesn't make sense for a user to go "back and forth" between the screens of your application, then you could still implement the application with multiple activities, using android.app.TabHost. This is what the Contact app uses, for example. Then each screen is just a sub-activity, and the whole app is really treated as a single activity. And if you want, you can use TabHost without actually having tabs. You can hide the tabs and enable navigation via buttons or menu items instead.

Neil Traft
  • 18,367
  • 15
  • 63
  • 70
  • thanks for the answer. in this case the app is a little game so the navigation through controls is not as standard. however, i understand that android haves some automatic handling of things when using activities, as the focused-control capability that you mentioned. – Alexander Fradiani Aug 08 '10 at 20:03