Skip to content Skip to sidebar Skip to footer

Fragment In ViewPager On Fragment Doesn't Reload On Orientation Change

I am working on developing an Android application which uses ActionBarSherlock and ViewPagerIndicator. The main activity is a SherlockFragmentActivity and users navigate between th

Solution 1:

I figured out the issue. The problem was when the configuration changed, Android would destroy and recreate the Activity, but the Fragments were not being destroyed. They were added back to the manager and due to the code were also being recreated. So the ViewPager which wasn't recreated when the new Fragment was created didn't reference it correctly. The fix for this was in the onTabSelected function I did a check for the Fragment already existing in the manager, and just used that instead of recreating it. I also had to add tags to every Fragment that was created so I could find the Fragment that I was looking for.

if (mCurrentTag != null && mCurrentTag.equalsIgnoreCase(mTag) && fragMgr.findFragmentByTag(mCurrentTag) != null) {
    mFragment = fragMgr.findFragmentByTag(mCurrentTag);
}

Post a Comment for "Fragment In ViewPager On Fragment Doesn't Reload On Orientation Change"