Activities or Fragments? A little sharing…

I was asked one day, if we want to code two different screens, should we go for activity-activity or fragment-fragment? So I share my knowing …

Well, so just pour it out here as well… and have my answer at the end…

Some history

In the beginning

When Android was first made back in 2008, Activity is there as a screen to hold all UI views that the user interacts with. If developer wanted 2 different screens, the usual way is to have 2 activities

The introduction of Tablet

Beginning Android 3.0, Fragment was introduced… It was mainly to cater for the need of tablet, which have a much wider screen than a phone.

Fragment could be view as subview within the activity, where by one activity could have more than one fragments. In a tablet, fragment could be used as a pane, where an activity could have 2 panes (or more), showing the data side by side

On the phone instead, the fragment could also be reused. But instead of having it as multi-pane, the fragment got swap in and out of the phone view.

--

--