10

I have an Activity with many, many views (200+) and now I'm separating it into fragments in order to decouple my code a bit. The question is - how does it influence on the performance?

  • Let's say I have N views hierarchically layed out in one layout and same amount of views separated in fragments - does it matter in terms of performance?
  • When I hide a fragment, hopefully its views are not being drawn? (so I can gain here).

Generally, if you could give me a link to some book / article about fragments performance I'd be very glad (googled all the Internet with no results).

Fenix Voltres
  • 3,448
  • 1
  • 29
  • 36

1 Answers1

1

Fragment is only something like sub-activity with own life cycle. So if you don't need display all view at the same time it's much better use fragments (or multiple activities). For decoupling code you can also create own view components. Main reason to use fragments is better phone/tablet compatibility. Or for elegant way how to swich only part of screen like in ViewPager.

But fragment increase memory usage of application. Particularly if you will keep multiple fragments in memory.

Best way is investigate implementation of fragments, its open source. Or simply add Log.d() to the methods to see what was called.

ATom
  • 15,960
  • 6
  • 46
  • 50