After reading posts on this exception, I can\'t understand what I need to do to correct this error. Besides, I can\'t even reproduce it... This happens sometimes on some dev
Your app crashes because the implementation of FragmentStatePagerAdapter
is incorrect.
// private var fragments: MutableList<Fragment> = mutableListOf() // <-- remove this line entirely
You mustn't keep a list of fragments in your Fragment*PagerAdapter
, because the system recreates the Fragments, and the one you'll be invoking in that list will never actually be added to the FragmentManager.
Something you can do is switch FragmentStatePagerAdapter
to FragmentPagerAdapter
, then you can apply App crash after activity has been killed in background and How to get elements of fragments created by ViewPager in MainActivity? .
To reproduce your crash, refer to Singleton object becomes null after app is resumed .