Share via


Fragment.RetainInstance Property

Definition

Control whether a fragment instance is retained across Activity re-creation (such as from a configuration change).

public bool RetainInstance { [Android.Runtime.Register("getRetainInstance", "()Z", "")] get; [Android.Runtime.Register("setRetainInstance", "(Z)V", "GetSetRetainInstance_ZHandler")] set; }
[<get: Android.Runtime.Register("getRetainInstance", "()Z", "")>]
[<set: Android.Runtime.Register("setRetainInstance", "(Z)V", "GetSetRetainInstance_ZHandler")>]
member this.RetainInstance : bool with get, set

Property Value

Attributes

Remarks

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: <ul> <li> #onDestroy() will not be called (but #onDetach() still will be, because the fragment is being detached from its current activity). <li> #onCreate(Bundle) will not be called since the fragment is not being re-created. <li> #onAttach(Activity) and #onActivityCreated(Bundle)<b>will</b> still be called. </ul>

Java documentation for android.app.Fragment.setRetainInstance(boolean).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to