• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps When to use a new Activity?!

I'm designing an App with several layers of menus (on the screen, not from the menu button) which lead to several content pages each.

Should this be just 1 activity and with each menu and content page changing the layout? If so how do I do this?

If I should use a different activty for each menu and content page, again how would I do this?

Thanks very much for any help.
 
Cheers, I'm glad someone thinks it's a good question rather than just me being stupid :p

Just to add a bit more detail to the original post.
I'm going to have about 6 menu screens, each with its own layout XML and about 30 content screens, each with their own XML.

I am wondering whether to make a separate activity for each of these screens which will call the layout view by setContentView(R.layout....) in onCreate(),

or

whether to have just 1 activity for the entire application which upon each button press just changes the layout to the corresponding XML. If it is best practice to do it this way, do you need to wipe the existing layout or would setContentView() in the onClickListener for a button press just be enough?
 
There seems to be 2 ways of doing this, with xml or dynamically.

I'm leaning toward the latter since Its easier for to understand, all the changes can be made in one place and the view redrawn from onClick events.. but I'm still looking at all the tutorials about this.

As soon as I have a definitive answer I'll post it up, unless someone else pips me to the post.
 
That preferences example doesn't seem to apply to me, but thanks. I'm not wanting to change any settings, just to navigate through the menus.

I've done a bit of the layout coding now and have about 5 listView submenu screens, defined in XML, and each of those point to a further 5 relativeLayout Content screens, again defined in XML.

As GIR said this means I can do all the changes in 1 activity from the onClick(). I'd use a switch with a different case for each button that was pressed, but with each 5 menus and 5 content per menu that's 25 'case' to go through whenever a click is registered which seems bad design.

And secondly what is the code used to change layout? Do you need to clear the current layout or do you just set it again with setContentView()?
 
Ok I've worked it out and I've got 27 Menus, each of these is a ListActivity and 62 Content Pages (each of these is an activity calling a RelativeLayout and some onClick Listeners).

In total this is 89 activities, is this too many for one application? I like the idea of having a different activity per page as that means the user can just press the Back button on their phone to go back up the menus rather than coding in one myself.

But yeah, is this too many activities for one app? It is likely at a given time the user probably won't use more than 10 of them.
 
Hmm, can only think that test it on a real device to see what happens, but that does seem a lot.

This is why when it comes to menu screens I simply use dynamic screens and incude a back button.
I keep track of screen (menu) navigation with a string...

If you want me to test it on my real phone (ZTE Racer with 2.1 ) then post up the .apk and i'll get back to you.

All the best
GIR
 
I've so far got 1 main menu, a sub menu then a content page. Each one has its own activity. It's working smoothly on my Samsung Galaxy SII but this is a very fast phone so not sure how it would work on a medium range one.

It shouldn't take me too long to create all the content (what with copy/paste and find/replace) so will just do it with each screen having its own activity then see how it works. Thanks for the offer, may take you up on that later!
 
Back
Top Bottom