IllegalStateException: is not currently in the FragmentManager

后端 未结 12 2444
予麋鹿
予麋鹿 2021-01-31 08:40

I know it sounds like a duplicate of FragmentStatePagerAdapter IllegalStateException: is not currently in the FragmentManager but his solution isn\'t relevan

12条回答
  •  忘掉有多难
    2021-01-31 09:05

    The FragmentStatePagerAdapter is a horrible piece of code riddled with bugs acknowledge or not by Google and so I use this code to fix this particular crash:

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            // Yet another bug in FragmentStatePagerAdapter that destroyItem is called on fragment that hasnt been added. Need to catch
            try {
                super.destroyItem(container, position, object);
            } catch (IllegalStateException ex) {
                ex.printStackTrace();
            }
        }
    

提交回复
热议问题