user6798995 user6798995 - 18 days ago 10
Android Question

Android tabbed activity losses data when slide

I created tabbed activity using view pager with three fragments (f1,f2,f3), if I made changes to f1 then when I slide f2 get back out won't lose the data but when I slide to f3 the changes on f1 were lost ,I want all the data to persist while sliding, how to do that ?

Answer

Try to change Offset Page Limit of your viewPager like below.

mViewPager.setOffscreenPageLimit(3);

This method:

Sets the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state.

https://developer.android.com/reference/android/support/v4/view/ViewPager.html