Saving UI on orientation change - onSaveInstanceState not working as expected if retaining Fragment

前端 未结 1 984
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-01 21:04

Using compat lib v1 (not using v2|3 because of certain bugs); a variation of this question.

I have a fragment whose UI has various controls whose state I want to maintai

相关标签:
1条回答
  • 2021-02-01 21:35

    If you use setRetainInstance(true) then of course the bundle is null. The fragment is not destroyed but only detached from the current activity and attached to the new activity. Only when the fragment is destroyed do you get a bundle with the values you saved in onSaveInstanceState. Just remove setRetainInstance(true) and use the saved values in onCreateView() to setup your custom views.

    0 讨论(0)
提交回复
热议问题