life cycle callbacks of fragments are not called accordingly
I have a main activity with view pager and three action tabs "fragment". and i implemented the life cycle callbacks for each of the main activity and the
three fragments. and in each of the life cycle call back i placed a log statements indicates which life cycle callback being called to know how
the action bars with view pager behaves. at run time i perceived a strange behaviour which i cant understand or attribute it to any reason.
In the ViewPager, fragments are being created ahead of time.
That means, that your Frag_2 is not visible yet (because Frag_1 covers the entire screen), but it still creates the view beforehand, so scrolling to Frag_2 will be smooth.
By default, the ViewPager preloads one fragment on each side. So if you would set the start position of the ViewPager to Frag_2, it would load Frag_1 and Frag_2 as well, because they are the neighbors.
You'll notice that Frag_3 will be created when you swipe to Frag_2
Check the setOffscreenPageLimit method, you can use it to Set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state. By default it set 1, thats the reason because your have that behaviour..
Asked in February 2016Viewed 3,470 timesVoted 5Answered 2 times