As I’m making progress on my journey, towards the newer parts of the Android API, I’m starting to notice that the further I get from the earlier versions, the less documentation and information I find. I actually spent an hour or two looking into why my last three Fragments wouldn’t go through the onCreateView(LayoutInflater, ViewGroup, Bundle) from the start, and the answer is actually quite reasonable…
…it turns out that it’s behaving just like any other ordinary adapter, not preloading more views than necessary! In my case I had five fragments that I wanted to setup at the start of the FragmentActivity, but that doesn’t seem to be an option.
With that said, I’ll be looking into suitable replacements for my current thoughts, and hopefully manage to get it working as planned. Rest assured – I’ll edit this post if I come up with something great!
– Edit –
I actually forgot to come back with the solution, but I’ll be updating the post to address the comment by bp below. What I did to solve this was to use one of the newer ViewPager methods (added in a later compatibility package) called .setOffScreenPageLimit(int). As you might’ve figured out, the ViewPagerAdapter keeps a maximum of three Fragments active at any given time ([Previous if applicable][Current][Next if applicable]), but by using the .setOffScreenPageLimit(int), you manually declare (thus deciding) how many pages it should be keeping before recycling them. Obviously, the more Fragments you keep in memory, the more memory your app consumes so it’s a fine line between helping out and the direct opposite. In other words – use it wisely.