问题
I have 3 tabs in my application. In my first tab I need to read JSON data from URL and using the user location. It takes about 2-3 seconds to load the page. My problem starts when I implemented tabs, and now every time im swiping next and back, the info is re-fetched.
I tried the following solution: I moved my method to the MainActivity, and created a variable named "isUpdated" and updated it to 1 if the info has been fetched successfully. since then, the tab data is gone after swiping and it shows blank empty tab. I understand that the tab data is wiped after swiping to another tab, but I need to save the tab content.
How I can save the tab information and show it after the user swiped to the next tabs, without re-fetching the data over and over again?
回答1:
if you are using ViewPager then set your off screen page limit to something different
for example
mViewPager.setOffscreenPageLimit(2);
should be enough for 3 tabs
来源:https://stackoverflow.com/questions/32212032/saving-tab-information-after-swipe