简体   繁体   中英

How to save data when fragment in BottomNavigationView is changed?

In my app, I use BottomNavigationView and on each fragment I have some elements. On changing fragments my data that download is lost. How can I solve it?

You can use ViewPager.setOffscreenPageLimit() like this:

ViewPager pager = (ViewPager) findViewById(R.id.viewPager);
pager.setOffscreenPageLimit(2); //2 is number of pages that you want keep in memory and don't load again on click at its item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM