简体   繁体   中英

list starts loading from the beginning after screen rotation

In my fragment I have list. This list is is constantly filling. But after screen rotation list starts loading from the beginning. And the data that was in the vertical orientation is lost because in the horizontal orientation the list starts to load again. So, I added all what I could read in the internet: in my Manifest file:

android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"

in Activity class:

if (savedInstanceState == null) {
            firstFragment = FirstFragment()
            supportFragmentManager
                .beginTransaction()
                .add(R.id.frameLayout, firstFragment!!, "firstFragment")
                .commit()
        } else {
            firstFragment = supportFragmentManager
                .findFragmentByTag("firstFragment") as? FirstFragment
        }

but it did not help.

Please set setRetainInstance(true); in fragment code.

It will prevent recreating fragment instance.

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