Android fragments setRetainInstance(true) not works (Android support library)

后端 未结 2 1372
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 02:30

I have a problem with saving fragment state. I try to use setRetainInstance, but cant make it work((( I change a state to 2 using button1, but after changing screen orientat

相关标签:
2条回答
  • 2020-12-20 03:13

    There isn't anything wrong with the code you posted. If you have the fragment implemented correctly, it should be giving you a state of 2. Maybe you could post your activity and xml files. There error must be somewhere else.

    0 讨论(0)
  • 2020-12-20 03:16

    Your fragment will only get re-used if you give the fragment an Id in the layout, change

    <fragment
        android:name="ru.ee.TestFragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    

    to be

    <fragment
        android:id="@+id/a_fragment"
        android:name="ru.ee.TestFragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    
    0 讨论(0)
提交回复
热议问题