Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fragment reloads completely again on tab selection #65

Closed
vj-1023 opened this issue May 3, 2016 · 6 comments
Closed

Fragment reloads completely again on tab selection #65

vj-1023 opened this issue May 3, 2016 · 6 comments
Assignees
Labels

Comments

@vj-1023
Copy link

vj-1023 commented May 3, 2016

@aurelhubert

Hi,
I m new to android & I thank you for such a simple and neat library.
Although there is a small issue, This is a very fundamental problem which i faced, may be not completely linked to the library but yes it would make the implementation better.

I according to your documentation setup my activity & several fragments which i want to show for every tab on it's click. The problem here is my fragments make network calls to fetch data from the database to show lists & recycler-views !
but every time i reselect the tab, the onCreate(), onCreateView(), onActivityCreated() is called which makes my app to call for the data again & again which is not required ! once the feed data is loaded we don't need to reload it again everytime the tab is selected.
is there a work around for this, that the fragment doesn't reload again and app is efficient on data usage.

@ghost
Copy link

ghost commented May 12, 2016

have the same problem

@jatin-lakhani
Copy link

+1

@aurelhubert
Copy link
Owner

@vj-1023 @studyfordream @jatin-lakhani Hi guys, sorry for the delay of my answer. I'm currently working on an app which includes this library and I've tried to make something smooth and efficient (BTW, the demo is very simple, it doesn't show how to manage efficiently fragments, it's just here to show that you can manage one or more fragments per tab).

My solution (which is certainly not the best one) is to use a ViewPager to host the fragments. I have slightly modified the ViewPager class for my needs (mainly to avoid the swipe between the pages). Why use the ViewPager? Because this class is already ready to manage pages (and so fragments), and you can use the method setOffscreenPageLimit to load all your tabs at the beginning. It will results in a very smooth navigation between tabs (and the methods onCreate(), onCreateView() and onActivityCreated() will not be called every time you display a tab).

If you need an example, I could improve the demo to show you how I have implemented it (and maybe some users will have ideas to improve the code).

@aurelhubert aurelhubert self-assigned this May 18, 2016
@jatin-lakhani
Copy link

@aurelhubert

Thanks for the replay.

Its better for us if you provide demo as you have already implemented.

Thanks

@jagatappv
Copy link

@aurelhubert
its kind request you to post your demo ASAP.

@aurelhubert
Copy link
Owner

@vj-1023 @studyfordream @jatin-lakhani @jagatappv Hi guys, the demo has been updated with a AHBottomNavigationViewPager. You can check the classes here: https://github.com/aurelhubert/ahbottomnavigation/tree/master/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants