A
A
Artem2012-12-19 12:12:02
Android
Artem, 2012-12-19 12:12:02

Proper organization of an application with fragments?

I'm putting together an application. The app uses a ViewPager that toggles multiple (3-4) fragments. The first fragment contains the ListView, it is extremely important and should always exist in memory while the application is open, no matter what page the ViewPager is on. The rest are generally less fundamental, even if they are updated.
The crux of the matter is what. As far as I know, ViewPager only stores pages to the left and right of itself in memory. Will the first fragment be destroyed from memory if the third one is selected? Where is it better to fill the ListView with data from the first fragment - in the Activity or still in the class of the first fragment?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
erakitin, 2012-12-19
@bartwell

If the Fragment is in the ViewPager, then it will not work to save the state of the fragment manually (at least I did not succeed, I tried many methods that worked just in fragments). But, you can tell the ViewPager how many screens to store.

mViewPager.setOffscreenPageLimit(4);

In my case, this turned out to be the solution to the problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question