How can I switch between two fragments, without recreating the fragments each time?

后端 未结 10 1888
孤独总比滥情好
孤独总比滥情好 2020-12-08 00:19

I\'m working on an android application, that uses a navigation drawer to switch between two fragments. However, each time I switch, the fragment is completely recreated.

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 01:02

    this is a little late response. if you're using view pager for fragments, set the off screen page limit of the fragment to the number of fragments created.

    mViewPager.setOffscreenPageLimit(3); // number of fragments here is 3
    

提交回复
热议问题