Skip to content Skip to sidebar Skip to footer

How To Cache A Fragment View

I'd like to cache a fragment view. My Activity has swipeable tabs and each tab calls a different fragment. But when i swipe between tabs the transition seems a quite slow because o

Solution 1:

This is because internally by default the pager loads a maximum of 3 pages (fragments) at the time: the one displaying, previous and next so if you have 5 fragments this will happen while you move from first to last: (where x is a loaded fragment)

xx000 -> xxx00 -> 0xxx0 -> 00xxx -> 000xx

Try using

myPager.setOffscreenPageLimit(ITEMS_COUNT-1);

This will tell the pager to keep all of them in memory and not destroy/create with every swipe (keep a close look on the memory management)

Post a Comment for "How To Cache A Fragment View"