Search code examples
androidperformanceandroid-fragmentsandroid-activityandroid-navigationview

Performance improvements when using Activities instead of Fragments with complex NavigationDrawer components?


I have 5 complex Fragments for each Navigation menu click. However, I am not sure if I should use activities instead of fragments, because all my fragments are quite complex and expensive.

Since they are all fragments, they are also running on ONE Activity.

My question now is, would I benefit from using activities instead of fragments ?

I do know the differences of Fragments, activities. I'm just not sure if I should store all the complex fragments in one activity, or just use multiple activities instead of fragments in a navigationdrawer. I'm scared that all the fragments will consume too much ressources

Thanks a lot.


Solution

  • This is not an expert response, but just visually I never saw Fragments perform better or worse that Activities. I also had a Navigation Drawer with activities and fragments. At the same time, writing Fragments is easier than Activities if you need to pass information along, that's a big win for Fragments. If your application lags, better consider the following points:

    • Do not run any expensive operations on the UI thread. Examples are database queries, internet calls, populating long Listviews or RecyclerViews. Use an AsyncTask for that purpose.

    • Avoid very complicated nested layouts. If possible, use a ConstraintLayout which allows you to place items arbitrarily without nested layouts.

    • Use appropriate animations if the user has to wait. It is much more rewarding than staring at a frozen screen.

    • Check your code against the Google's Best Practices for Performance.

    If you have a more specific point where your application is getting slow, please post your code and describe the problem in more detail.