What is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter?

后端 未结 7 2173
傲寒
傲寒 2020-11-22 12:31

What is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter?

About FragmentPagerAdapter Google\'s guide

7条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 13:11

    FragmentStatePagerAdapter:

    • with FragmentStatePagerAdapter,your unneeded fragment is destroyed.A transaction is committed to completely remove the fragment from your activity's FragmentManager.

    • The state in FragmentStatePagerAdapter comes from the fact that it will save out your fragment's Bundle from savedInstanceState when it is destroyed.When the user navigates back,the new fragment will be restored using the fragment's state.

    FragmentPagerAdapter:

    • By comparision FragmentPagerAdapter does nothing of the kind.When the fragment is no longer needed.FragmentPagerAdapter calls detach(Fragment) on the transaction instead of remove(Fragment).

    • This destroy's the fragment's view but leaves the fragment's instance alive in the FragmentManager.so the fragments created in the FragmentPagerAdapter are never destroyed.

提交回复
热议问题