androidandroid-studiomaterial-designandroid-slidingpagerslidingtabstrip

SlidingTabLayout: why preload next tab?


I've implemented SlidingTabLayout on my application, following https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabLayout.java and tutorial all google. All works, but I don't understand why when I do

  viewPager.setAdapter(viewPageAdapter);
  slidingTabLayout.setViewPager(viewPager);

are automatically called:

  getItem(0);
  getItem(1);

Instead of

 getItem(0);

that's the tab of default. Is like a pre-load of the next tab for performance optimization? How can I avoid it?


Solution

  • Is like a pre-load of the next tab for performance optimization?

    Yes.

    How can I avoid it?

    Don't use ViewPager. The idea behind ViewPager is that the user can swipe between pages. That requires the pages on either side of the current page to be loaded, so the animation between pages can happen smoothly.