One Activity and all other Fragments [closed]

It depends on the app you are creating. I’ve created several apps using both approaches and can’t say one way is always better than the other. The latest app I created I used the single Activity approach and a Facebook style navigation. When selecting items from the navigation list I update a single Fragment container to display that section.

That said, having a single Activity also introduces a lot of complexities. Let’s say you have an edit form, and for some of the items the user needs to select, or create, requires them to go to a new screen. With activities we’d just call the new screen with startActivityForResult but with Fragments there is no such thing so you end up storing the value on the Activity and having the main edit fragment check the Activity to see if data has been selected and should be displayed to the user.

What Aravind says about being stuck to a single Activity type is also true but not really that limiting. Your activity would be a FragmentActivity and as long as you don’t need a MapView then there are no real limitations. If you do want to display maps though, it can be done, but you’ll need to either modify the Android Compatibility Library to have FragmentActivity extend MapActivity or use the the publicly available android-support-v4-googlemaps.

Ultimately most the devs I know that went the one Activity route have gone back to multiple Activities to simplify their code. UI wise, on a tablet, you are some times stuck using a single Activity just to achieve what ever crazy interaction your designers come up with 🙂

— EDIT —

Google has finally released MapFragment to the compatibility library so you no longer have to use the android-support-v4-googlemaps hack. Read about the update here: Google Maps Android API v2

— EDIT 2 —

I just read this great post about the modern (2017) state of fragments and remembered this old answer. Thought I would share: Fragments: The Solution to All of Android’s Problems

Leave a Comment