0

I have one fragment that contains two fragments inside.

Every fragment is loading some names from database and displays them as a list with a limit of 50.

At start my adapter has 50 elements, when user scrolls down another 50 is beign loaded, then adapter is with 100 elements.

Now whenever I rotate the device, my data in adapter is messed up, that is my question is there any way to save my state of childFragment? without using parceable and parcel the whole 100 elements together with current position?

user3274539
  • 687
  • 2
  • 8
  • 18

1 Answers1

0

You should use Fragment's setRetainInstance(boolean) feature.

Setting

setRetainInstance(true);

to a Fragment containing the child Fragments should do.

Control whether a fragment instance is retained across Activity re-creation (such as from a configuration change). This can only be used with fragments not in the back stack. If set, the fragment lifecycle will be slightly different when an activity is recreated:

Understanding Fragment's setRetainInstance(boolean)

Community
  • 1
  • 1
Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99