Reputation: 2021
Friends I have 4 tabs A, B , C, D in my App All 4 tabs are fragments , For tabs I am using PagerSlidingTabStip, In view Pager adapter I am using FragmentStatePagerAdapter
My problem is when I toggle between TAB A and TAB B it is very smooth but once I click TAB C it takes time and its also called Fragment D
Now If I toggle between TAB C and TAB D again it is smooth but if I click on TAB A or TAB B then again it takes time and if I click on TAB B, TAB A also get called in background which I can see from log cat
I am using loader manager in Fragment A , B , and D to loader data from database .
I have no idea why it is happening, Can Any one please explain me , it making my app slower in the last stage when I am about to release
Upvotes: 0
Views: 847
Reputation: 1
Important is that the fragment that contain array list or whatever you are passing into it are executing in the same activity in which you are passing the fragment that's why your fragment are slowly swiping, i just take 3 days to find out the solution. so the solution is that execute your data or load your data in to main class from where your are calling your fragment or from view pager whatever from where you are calling your fragment.
Upvotes: 0
Reputation: 1629
What happens is that your fragments are created lazy upon need - If you're on A then B is created and scrolling between them is smooth. Once you jump to C it's created together with D - that's why scrolling between them is smooth.
The reason it's not smooth, is that the creation of your fragments is heavy. You should check your onCreateView or example to find out any heavy lifting there. Maybe there are stuff that can be moved into the BG there.
Upvotes: 0
Reputation: 34
You can use setOffscreenPageLimit (int limit) for you view pager. if you follow this link it will help you out. http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit(int)
Upvotes: 2