Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FragmentStatePagerAdapter not removing fragments if parent fragment removed

I am facing memory leak because some fragments are not removed. I have Activity that populates view with Fragment F1. This fragment has ViewPager and FragmentStatePagerAdapter associated with it. Adapter is feeling pager with another Fragment F2. Problem starts when in Activity I remove Fragment F1. Existing Fragments F2 are not removed.

any suggestions?

like image 367
wonglik Avatar asked Nov 03 '22 06:11

wonglik


1 Answers

Not sure if it is the same problem, but some time ago I had a problem with viewpager where the fragment lifecycle methods were never called and the problem was with the fragment manager.

So, when you create the adapter try passing childFragmentManager instead of supportFragmentManager and see if it fixes your issue.

like image 186
Mikel Avatar answered Nov 09 '22 09:11

Mikel