How to reset viewpager content on Android?
I have changed to use FragmentStatePagerAdapter
instead of FragmentPagerAdapter
, the problem is resolved. Hope this helps.
I think the best solution to reload fragments in another fragment is :
@Override
public void onPause() {
super.onResume();
List<Fragment> fragments = getFragmentManager().getFragments();
if (fragments != null) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
for (Fragment fragment : fragments) {
if (fragment instanceof Fragment) {
fragmentTransaction.remove(fragment);
}
}
fragmentTransaction.commitNowAllowingStateLoss();
}
}
Check for your use case whether commitNowAllowingStateLoss
or commitAllowingStateLoss
is necessary.