When developing an Android app, is there a rule of thumb for when you should stop changing layouts and instead switch to a new activity? What factors might influence the decision?
There are no hard and fast rules, but I've got a few personal ones:
I primarily think of how my users will use the back button. In an optimal app, the natural use of "back" to go through Activities is what I aim for. Each time a user might want to use back, that should be a new Activity. Of course, rules are meant to broken and sometimes you'll need to override the back button yourself to control a more complex interface.
Also, you shouldn't be tempted to call setContentView()
again. If you are tempted to redo the entire layout of the page, maybe you should move to a new Activity instead.
I would also check out this guide.
There should be a rule that says "don't setContentView() twice". As written in Application Fundamentals:
An activity presents a visual user interface for one focused endeavor the user can undertake
So modifying the purpose of a given Activity will actually make you life harder than saving you writing more code.