Share via


Fragment.OnSaveInstanceState(Bundle) Method

Definition

Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance of its process is restarted.

[Android.Runtime.Register("onSaveInstanceState", "(Landroid/os/Bundle;)V", "GetOnSaveInstanceState_Landroid_os_Bundle_Handler")]
public virtual void OnSaveInstanceState (Android.OS.Bundle? outState);
[<Android.Runtime.Register("onSaveInstanceState", "(Landroid/os/Bundle;)V", "GetOnSaveInstanceState_Landroid_os_Bundle_Handler")>]
abstract member OnSaveInstanceState : Android.OS.Bundle -> unit
override this.OnSaveInstanceState : Android.OS.Bundle -> unit

Parameters

outState
Bundle

Bundle in which to place your saved state.

Attributes

Remarks

Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance of its process is restarted. If a new instance of the fragment later needs to be created, the data you place in the Bundle here will be available in the Bundle given to #onCreate(Bundle), #onCreateView(LayoutInflater, ViewGroup, Bundle), and #onActivityCreated(Bundle).

This corresponds to Activity#onSaveInstanceState(Bundle) Activity.onSaveInstanceState(Bundle) and most of the discussion there applies here as well. Note however: <em>this method may be called at any time before #onDestroy()</em>. There are many situations where a fragment may be mostly torn down (such as when placed on the back stack with no UI showing), but its state will not be saved until its owning activity actually needs to save its state.

Java documentation for android.app.Fragment.onSaveInstanceState(android.os.Bundle).

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