简体   繁体   中英

Fragment is not attched to parent when application goes to background for long time

I have a fragmentA which has ViewPager which contains couple fragments lets say FragmentA-1 and FragmentA-2. If i keep app in background for more than 10 minutes and open app again, Fragment inside(ie FragmentA-1, FragmentA-2) viewpager get detached.

But click events of the view inside FragmentA-1 and FragmentA-2 works fine and when I try to update UI from parent fragment ie FragmentA then it shows view as null;

 mFrontPhotoFragment = AddCardPhotosFragment.newInstance();
    mBackPhotoFragment = AddCardPhotosFragment.newInstance();
    mCardsFragment.add(mFrontPhotoFragment);
    mCardsFragment.add(mBackPhotoFragment);
    PagerAdapter pagerAdapter = new PagerAdapter(getChildFragmentManager(), mCardsFragment);
    mCardsViewPager.setAdapter(pagerAdapter);

This happens on specific devices with low configuration. How can i fix this

Thanks in advance.

In view pager, Fragment might be recycled it some times. Try setting page limit.

You can call viewpager.setOffscreenPageLimit(k) to cache all entities of ViewPager from nk to n+k .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM