Andy
Andy

Reputation: 2774

Android Activities and Views

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?

Upvotes: 3

Views: 1220

Answers (2)

ognian
ognian

Reputation: 11541

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.

Upvotes: 2

Dan Lew
Dan Lew

Reputation: 87420

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.

Upvotes: 3

Related Questions