-1

While I understand why we need Fragments ( independent reusable modules, each handle its own UI which can change for tablets and phones, etc... ) if I ignore those reasons and try to keep it simple having a layout with 3-4 Fragments with their lifecycles sounds more "expensive" than a layout with 3-4 ViewGroup items.

Each time the Fragments need to create their View they have a whole lifecycle ( onAttach -> onCreate -> onCreateView ... ). That means, I guess, using more system resources than an Activity with one Layout.

Even worst if I have something like a list ( not a ListFragment just 10 LinearLayouts items ) shouldn't it be much more faster a UI with 10 ViewGroup items than 10 Fragments?

test2558
  • 335
  • 4
  • 8
  • 3
    did you experience any serious slowdown? if not, would you care if your screen layouts in 136ms vs 129ms? – pskink Jul 20 '13 at 05:08

1 Answers1

1

Right, Fragments will be slightly slower.

However, faster term is quite relative. And depending on the exact application the same absolute difference in time can be considered differently. Be aware of premature optimization too.

I've prepared simple measurement: two RelativeLayouts with 4 TextView each added as simple layouts and the same layouts added as 2 Fragments (all done via xml). I've measured the time relative layouts were completely drawn using ViewTreeObserver. For tested case the difference was < 10 ms most of the time on my device. I would suggest to do same measurements for Your case and only after that decide if it worth to remove Fragments, because they are giving lot of advantages in case of flexibility, ease of support, reusage, code complexity etc.

Community
  • 1
  • 1
sandrstar
  • 12,503
  • 8
  • 58
  • 65