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?
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).
A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments cannot live on their own--they must be hosted by an activity or another fragment.
Each tab will have a fragment to hold the products. The tabs could either held in activity or a fragment. I do find fragments a slightly faster than activities but really its not something you would really notice in most cases. Regardless if they was intended for speed or not they still seem/feel little quicker.
A Fragment is a combination of an XML layout file and a java class much like an Activity . Using the support library, fragments are supported back to all relevant Android versions. Fragments encapsulate views and logic so that it is easier to reuse within activities.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With