Fragments seem to be very nice for separation of UI logic into some modules. But along with ViewPager
its lifecycle is still misty to me. So Guru thoughts are b
What is that BasePagerAdapter
? You should use one of the standard pager adapters -- either FragmentPagerAdapter
or FragmentStatePagerAdapter
, depending on whether you want Fragments that are no longer needed by the ViewPager
to either be kept around (the former) or have their state saved (the latter) and re-created if needed again.
Sample code for using ViewPager
can be found here
It is true that the management of fragments in a view pager across activity instances is a little complicated, because the FragmentManager
in the framework takes care of saving the state and restoring any active fragments that the pager has made. All this really means is that the adapter when initializing needs to make sure it re-connects with whatever restored fragments there are. You can look at the code for FragmentPagerAdapter
or FragmentStatePagerAdapter
to see how this is done.