Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it not recommended to use activities with bottom navigation

As mentioned here, and some other places that it is better to use fragment instead of activities with bottom navigation

If it is not recommended, then i have few questions,

I will have 5 items in bottom navigation, all of the items will retrieve data from web services, and have large amount of data, each will have to do parsing and have complex layouts.

Now my question is can an activity with these type of fragments can create any impact on performance.

and why it is not recommended to use activities with bottom navigation.

like image 303
Taha Kirmani Avatar asked May 01 '18 15:05

Taha Kirmani


1 Answers

If I was in your position, i'd use a view pager in combination with the bottom navigation component. This will manage the creation/deletion of fragments and should address your concerns with performance. It will also preload the previous/next screens for the user and can make the network calls on those screens before the use even goes to them.

Here is a pretty simple link showing this being done: http://www.truiton.com/2017/01/android-bottom-navigation-bar-example/

To address your question why not to use activities, this kind of widget and situation is exactly what fragments were created for. They can easily be nested inside of an activity and swapped between. Activities weren't created to be nested inside one another. Instead you'd have to have a bottom navigation view as part of each of the activities, and manage the switching for each of them. You'd lose the animation of swapping between them. Not only would this create a lot of unnecessary and duplicate code, but activities are heavier and you lose the nesting aspect.

This is exactly what fragments are meant for. I've followed this paradigm on several applications that sound similar to yours, network requests on each screen, fairly complex layouts on each tab. This is a pretty standard way to go about it. Hopefully this helps, let me know if you need a further explanation.

like image 130
Kyle Avatar answered Sep 21 '22 20:09

Kyle