Search code examples
androidandroid-activitymenuandroid-fragmentsandroid-4.0-ice-cream-sandwich

Activities vs Fragments for static menu bar


I've developed like 5 Android applications using only Activities (and from time to time Fragments for ViewPagers for instance).

I have to develop a new application targeting Android ICS for tablets and handsets, with a very simple and static menu bar on the top (like 4 buttons on a single line). I don't need any single-pane / multi-pane layout depending on if the user has a handset or a tablet.

Each button of the menu bar will open a different screen, always keeping the menu bar on the top of the application. My question is if using Fragments for each screen instead of Activities is the proper way to achieve this.

Apart from avoiding some code duplication (basically the behavior of the menu bar), I don't see any advantage of using Fragments.

EDIT

First of all thanks a lot for answering my question so precisely and so fast.

Your answers have been very helpful for me : for instance I was afraid of having just one single Activity one my app, but I now understand it's rather a good thing.

You wanted to know what my application will actually do, so... there will be like 4 different screens : a News screen, a Videos screen (with live streaming video players), a Search for past videos screen and a basic Contact screen.


Solution

  • My question is if using Fragments for each screen instead of Activities is the proper way to achieve this.

    Your scenario is pretty simple and you could go either way. I would choose fragments over activities mainly because:

    1. always keeping the menu bar on the top of the application. - With a fragment based app you could have a smoother transition between the various screen(and it will also allow you to keep in place the buttons bar).

    2. easier communication between the various screens of the app as you'll have all the fragments in one parent Activity(but as I don't know what your app does I'm not sure this is something relevant).

    3. Your app may be small now but you may get new ideas/requests to improve it in the future and this may be an easier task to do when your app is composed from fragments(which should be designed as loosely coupled components). Again, not knowing what your app does, this may or not may be relevant. An example scenario would be the need(in the future) to insert a ViewPager for the content of the app(so you allow the user to also swipe to a page not only click a Button). Using fragments this would be very simple as you need to setup the ViewPager and insert the content fragments, using Activities would mean a lot more refactoring.