Is using Fragment's setRetainInstance(true) really a good practice to handle rotation change

后端 未结 2 330
死守一世寂寞
死守一世寂寞 2021-01-30 17:39

I\'m referring to Why use Fragment#setRetainInstance(boolean)?

The reason I ask so is for Activity to handle rotation, Official Activity Documentation encou

2条回答
  •  孤独总比滥情好
    2021-01-30 18:09

    Because you are misunderstanding its use. setRetainInstance(true) should only be used in fragments that are like solo elements/modules. Fragment that handle sockets etc. an don't have a GUI really benefit from being retained. Fragments with a GUI should probably not use setRetainInstance(true). Also any fragments that goes to the backstack shouldn't use setRetainIstance(true).

    You could generalize it to any fragment which handles only data/connection etc. should use setRetainInstance(true). But there is a multitude of different ways to use Fragments, which wouldn't benefit of setRetainInstance(true).

提交回复
热议问题