Reputation: 1270
referring at the diagram below:
http://developer.android.com/guide/components/fragments.html
Could someone please please explain why Google suggests to use 2 separate activities on a Phone and a single activity on a Tablet? If I have code in activity A to manage Fragment B (for a Tablet) why should I repeat the same code in Activity B for a phone?
It seems that for a Phone I can still use 1 activity as well (only activity A) and replace fragments, this could reduce redundant code?
Thanks.
Upvotes: 2
Views: 646
Reputation: 4228
Rejinderi's solution should work. I think that either that implementation or the one from Google's example can be a reasonable choice. It depends on what you are trying to achieve.
Personally, I prefer Google's example for the following reasons:
ActivityA
is capturing JobB.FragmentB
without FragmentA
is (a bit) different, and breaking it into it's own activity helps separate that logic, and makes everything more readable.Upvotes: 0
Reputation: 11844
I get what you mean..
You could use a fragment container and replace the fragments, define interface for selection callback. Google just does it this way maybe its clearer for those who come from the activities world i guess.
Upvotes: 1
Reputation: 14700
The reason is, essentially, that phones are small. Really small. Tiny, in fact.
Take the classic scenario of an email application. The two fragments in that scenario would be the Message List (Fragment A) and Message Content (Fragment B). On a tablet, where you've got space, you can combine them into a single activity, concurrently on screen, comfortably. On a phone, however, you need to carefully manage your screen real estate, so you should split them into the choose-a-message phase (Activity A showing Fragment A) and the read-a-message phase (Activity B showing Fragment B).
By developing them as fragments, similar to user controls in other platforms, you can use the same fragments in the same codebase on a tablet and a phone, composing the activity from existing fragments.
Upvotes: 3