-3

I have an android app with a MainActivity which implements a menu with 5 buttons. Each button activates a different fragment.

Without using the "setOffscreenPageLimit(int limit)", every time I go from fragment to fragment, each fragment loads every single time. Using:

setOffscreenPageLimit(5) 

I understand that loads all of my 5 main fragments when starting my application. But I don't want this, because it is too heavy.

I want to implement this: "Load every fragment only when the user activates it, through choosing the menu button.Then keep it on memory , so when user goes back to this fragment, you don't have to load it again."

MLavoie
  • 9,671
  • 41
  • 36
  • 56
mitsos
  • 31
  • 3
  • 1
    "each fragment loads every single time" -- it shouldn't. Please provide a [mcve] demonstrating how you are setting up your `ViewPager` and explain, in detail, how you are determining that "each fragment loads every single time". – CommonsWare Jan 28 '17 at 17:00

1 Answers1

0

From the scratchy details you have provided, I understand that, you want to show fragment when it's displayed on the screen, you don't want it to load when fragment is in background. For this you can try this:

https://stackoverflow.com/a/25001920/6383029

Community
  • 1
  • 1
Mustansir
  • 2,445
  • 1
  • 21
  • 32