0

I am designing a viewpager using a FragmentPagerAdapter.

Now we know, The view pager by default stores one page before and one page ahead of the current page being viewed for smoother transitions. I want to know is there any way to eliminate this behavior.

Actually, I want to test the product in conditions of low memory, so app should use less memory that's why i want that the page is not stored in the memory. I have only two pages in the view pager.

MFP
  • 1,133
  • 9
  • 22
mishigun
  • 295
  • 3
  • 11

1 Answers1

0

I think this question has already been discussed. Please see the link below. ViewPager.setOffscreenPageLimit(0) doesn't work as expected

Community
  • 1
  • 1
Syed Arsalan Kazmi
  • 752
  • 1
  • 7
  • 16
  • Actually I want to test a low memory condition. I want the fragment to be called every time – mishigun Nov 26 '15 at 12:15
  • should you not load as many fragments as you can to test a low memory condition rather than loading minimum number of fragments? – Syed Arsalan Kazmi Nov 26 '15 at 12:38
  • Actually I have two fragments only. They have a list of view inflated manually which contain a spinner each. Each time a spinner is selected the position along with a tag is put in a map. So every time the onCreateView of the fragment is called all the spinners would be set from the map. So I need to call the onCreateView for each page change as I need to verify that the spinner item are being correctly selected. – mishigun Nov 26 '15 at 12:48
  • Why not save the values you want in shared preferences and load them whenever needed? – Syed Arsalan Kazmi Nov 26 '15 at 12:57
  • Can you tell me the reason for this. I have 3 pages in view pager and the offScreenPageLimit is 1. Now first page 0 is viewed then I go to page one and then I go to page 2. Now when I go back to page 1 again why only the onCreateView of the fragment is called and why not onCreate is also called? – mishigun Nov 26 '15 at 17:35