Pattern “One activity, multiple views”: Advantages and disadvantages

We cannot use TabActivity, ListAcivity, MapActivity. But there are some tricks to go without them.

You have to use MapActivity if you want to use MapView. You have to use PreferenceActivity if you want to use preference XML.

It is necessary to keep history by ourselves. But it’s not so difficult to develop.

The difficulty in managing your own history will depend greatly on what the history needs to be. Implementing history for a simple wizard will be fairly easy. However, that is a particularly simple scenario. There is a fair amount of history management code in Android that you would have to rewrite for arbitrary other cases.

You also forgot:

#5. You will be prone to leak memory, because you will forget to clean up stuff, and Android will not clean up stuff (since it assumes that you will be using many small activities, the way they recommend).

#6. Your state management for configuration changes (rotation, dock, SIM change, locale change, multiple displays, font scale) will be more complicated because now you also have to figure out what extra stuff (e.g., history) need to be part of the state, and you have deal with all of them at once rather than activity-at-a-time.

#7. Having multiple entry points for your application becomes more challenging (e.g., multiple icons in launcher, app widget linking to some activity other than the main one, responding to etc.).

It’s faster to change the content of current activity than to start another activity

For most modern Android devices, the speed difference will not be significant to most users, IMHO.

If we have only one activity-context it’s simpler to find and solve problems with memory leaks

Except that you still have more than “one activity-context”. Remember: your activity, large or small, is still destroyed and recreated on configuration changes.

What do you think about this pattern ?

Coase’s “nature of the firm” theory says that businesses expand until the transaction costs for doing things internally become higher than the transaction costs for having other firms do the same things.

Murphy’s “nature of the activity” theory says that the activity expands until the transaction costs of doing things internally become higher than the transaction costs for having other activities do the same things. Android developers will tend towards a “user transaction” model for activities — things that are tightly coupled (e.g., steps in a wizard) will tend to be handled in single activity, and things that have little relationship (e.g., browse vs. search vs. settings vs. help vs. about) will tend to be handled in distinct activities.

Leave a Comment