-1

My app contains a ViewPager which holds 5 fragments. When fragment 1 is visible, it also calls fragment 2's onCreate method. I tried using onAttach, onMenuVisibility, etc. But I don't like how these perform in my app.

Is there a way to disable a fragment's onCreate being called when the adjacent fragment is visible?

grantespo
  • 2,233
  • 2
  • 24
  • 62

2 Answers2

0

ViewPager is loading next and previous pages accordingly to viewPager.setOffscreenPageLimit(). Default and min value is 1.

beeb
  • 1,615
  • 1
  • 12
  • 24
0

What I've found about it's that you need at least 1 fragment offset (check setOffscreenPageLimit()).

You can have a placeholder fragment if you want. But as viewpager enables you to swipe left/right, android always want to show a smooth movement to the side pages and that requires having the page previously loaded.

You can find more about this here: https://stackoverflow.com/a/10073916/3976716

Community
  • 1
  • 1
Juan Giorello
  • 333
  • 2
  • 13