What is the difference between FragmentPagerAdapter
and FragmentStatePagerAdapter
?
About FragmentPagerAdapter
Google's guide says:
This version of the pager is best for use when there are a handful of
typically more static fragments to be paged through, such as a set of
tabs. The fragment of each page the user visits will be kept in
memory, though its view hierarchy may be destroyed when not visible.
This can result in using a significant amount of memory since fragment
instances can hold on to an arbitrary amount of state. For larger sets
of pages, consider FragmentStatePagerAdapter
.
And about FragmentStatePagerAdapter
:
This version of the pager is more useful when there are a large number
of pages, working more like a list view. When pages are not visible to
the user, their entire fragment may be destroyed, only keeping the
saved state of that fragment. This allows the pager to hold on to much
less memory associated with each visited page as compared to
FragmentPagerAdapter
at the cost of potentially more overhead when
switching between pages.
So I have just 3 fragments. But all of them are separate modules with a large amount of data.
Fragment1
handles some data (which users enter) and passes it via activity into Fragment2
, which is just a simple ListFragment
. Fragment3
is also a ListFragment
.
So my questions are: Which adapter should I use? FragmentPagerAdapter
or FragmentStatePagerAdapter
?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…