ViewPager by default uses setOffscreenPageLimit(1)
, which means that it 'caches' one view to the left and another one to the right, so if you are on 2nd fragment and go to either 1st or 3rd, it will not reload. If you would go back to 1st and than 2nd, the 3rd would be reloaded.
setOffscreenPageLimit(0)
produces a warning (minimum has to be 1).
A solution would be to load use the setUserVisibleHint
in your Fragments to detect when they become visible, and handle loading/refreshing data there.
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
// load data here
}else{
// fragment is no longer visible
}
}
This answer is taken from this SO answer.