Understanding Fragment's setRetainInstance(boolean)

后端 未结 5 775
太阳男子
太阳男子 2020-11-22 04:46

Starting with the documentation:

public void setRetainInstance (boolean retain)

Control whether a fragment instance is retained across Activity re

5条回答
  •  离开以前
    2020-11-22 05:46

    setRetainInstance() - Deprecated

    As Fragments Version 1.3.0-alpha01

    The setRetainInstance() method on Fragments has been deprecated. With the introduction of ViewModels, developers have a specific API for retaining state that can be associated with Activities, Fragments, and Navigation graphs. This allows developers to use a normal, not retained Fragment and keep the specific state they want retained separate, avoiding a common source of leaks while maintaining the useful properties of a single creation and destruction of the retained state (namely, the constructor of the ViewModel and the onCleared() callback it receives).

提交回复
热议问题