Closed georrge1994 closed 1 year ago
I have resolved my problem with manually removing the old fragments from fragmentManager. I don't reuse old detached adapters, so I don't to have old instances of nested fragments in fragment manager.
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
super.onDetachedFromRecyclerView(recyclerView)
fragmentManager.beginTransaction().apply {
fragmentManager.fragments.forEach { fragment ->
if (fragment is NoteListFragment) {
detach(fragment)
}
}
}.commitAllowingStateLoss()
}
UPDATE: Also I had to add the same code for onAttachedToRecyclerView
before super call. Without it I still had a leak by screen rotation.
Too muach bugs, hacks and problems with viewpager2! There is my perfect solution with nested fragments in an another fragment, but I still have huge problems with stability (the fcking detaching adapter from GC). No memory leaks! But nested fragments are alive and go throw fragment-life-circle. Every time when I leave from screen and return back (restarted both fragments) I got one additional instance of NoteListFragment! Previous viewPager1 was not optimized, but it works! You have to retire the person who created this sht!
NotesFragment - Class with viewpager2:
NotesViewPagerAdapter:
NoteListFragment is inner fragment.