Ambran
Ambran

Reputation: 2627

Using a no-fragment activity instead of a one-fragment activity

While peer reviewing a colleague's code I noticed she created a new Activity and all functionality is just there without a Fragment.

In the old days of Android, this is what we did, but the last few years I and my peers always took the approach that every Activity should have at least one Fragment and no actual code should be written in the Activity apart from loading the Fragment of-course and maybe some higher end procedures.

I want to argue for always using at least one Fragment in every Activity, but I couldn't find compelling arguments about why it is better than a no-fragment Activity.

The out of the box argument I can think of is that it will be easier adding new fragments if needed, but if we know this will never be a necessity, why bother with a single fragment Activity?

Upvotes: 0

Views: 50

Answers (1)

ruby6221
ruby6221

Reputation: 286

Fragment is easier to extend and test, if you are writing another new feature, it is helpful for separating code. And you can also move your fragment code to another place easy.
Of cource, if you are sure that your code is very simple and stable, like demo or temp test code, you can also use Activity without fragment.

Upvotes: 1

Related Questions