tags:

views:

123

answers:

2

I am creating an android application that has a lot of different screens where the user can navigate to those screens using the buttons or list provided in those screens. What would be the best way to design the entire app's navigation flow? Should I map each screen to be View or an Activity? Can an design an entire android app with just one activity and many views, where each view represents one screen with many other UI elements (buttons, lists, images etc)

+4  A: 

I suggest you use for every "screen" that is significantly different from another screen (in both look and data that it is related to) a new activity. This gives you easier control and you don't have to mess up your code with plenty of variables to define different states. Using different activites you usually shouldn't have to worry about running in a undesirable or even undefined state.

To exchange data between activities you can use putExtra() to add "simple" data to an INTENT or for more complex data you can extend Application and use that instance as a singleton, which you then can access via (MyApplication)getApplication();

znq
+2  A: 

You really want to stay away from the single activity idea. That's actually an anti-pattern from the java model 1 web application days called "The magic servlet". I guess here it would be called "The magic activity". Each logical "screen" that the user interacts with should be an instance of the Activity class.

Modifying individual user interface elements based on user interaction is fine as long as it's just one or two elements, or just a portion of the screen, but for the most part you should be looking for reasons to split things out into their own activities, not looking for reasons to keep things together. In the long run it will make your code easier to maintain and understand.

MattC
I agree with this sentiment. However, when using a TabActivity the views _can_ be either Activities or Views, even if the content is significantly better. This is due to the overhead associated with creating an Activity.
Nate
Sorry, I meant "if the content is significantly different, not better" :)
Nate