I have an application with an activity and 3 swipable tabs(fragments). I have some heavily created UI elements inside tabs which take some time to be created and it's ok for the first run, but the views are recreated every time I swipe them.
When I select a tab, the other tab calls onStop() and when I select the previous tab again,onCreateView() is called again and view is repopulated which slows down and blocks UI thread.
What is the correct way to create fragments inside tabs ONCE and avoid recreating their view when swiping between other tabs?
To add to what CommnosWare stated, if you are using a view pager, you can simply call mViewPager.setOffscreenPageLimit(3);
to keep all three in memory. But if your UI is too heavy, you may notice some jank. So try revising your UI setup code.