Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 321
Andy Avatar asked Dec 06 '25 10:12

Andy


2 Answers

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.

like image 87
Dan Lew Avatar answered Dec 07 '25 22:12

Dan Lew


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.

like image 28
ognian Avatar answered Dec 07 '25 22:12

ognian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!