Android.App.Activity.OnSaveInstanceState Method
Called to retrieve per-instance state from an activity before being killed so that the state can be restored in Activity.OnCreate(Android.OS.Bundle) or Activity.OnRestoreInstanceState(Android.OS.Bundle) (the Android.OS.Bundle populated by this method will be passed to both).

Syntax

[Android.Runtime.Register("onSaveInstanceState", "(Landroid/os/Bundle;)V", "GetOnSaveInstanceState_Landroid_os_Bundle_Handler")]
protected virtual void OnSaveInstanceState (Android.OS.Bundle outState)

See Also

Activity.OnCreate(Android.OS.Bundle)
Activity.OnRestoreInstanceState(Android.OS.Bundle)
Activity.OnPause

Parameters

outState
Bundle in which to place your saved state.

Remarks

Called to retrieve per-instance state from an activity before being killed so that the state can be restored in Activity.OnCreate(Android.OS.Bundle) or Activity.OnRestoreInstanceState(Android.OS.Bundle) (the Android.OS.Bundle populated by this method will be passed to both).

This method is called before an activity may be killed so that when it comes back some time in the future it can restore its state. For example, if activity B is launched in front of activity A, and at some point activity A is killed to reclaim resources, activity A will have a chance to save the current state of its user interface via this method so that when the user returns to activity A, the state of the user interface can be restored via Activity.OnCreate(Android.OS.Bundle) or Activity.OnRestoreInstanceState(Android.OS.Bundle).

Do not confuse this method with activity lifecycle callbacks such as Activity.OnPause, which is always called when an activity is being placed in the background or on its way to destruction, or Activity.OnStop which is called before destruction. One example of when Activity.OnPause and Activity.OnStop is called and not this method is when a user navigates back from activity B to activity A: there is no need to call Activity.OnSaveInstanceState(Android.OS.Bundle) on B because that particular instance will never be restored, so the system avoids calling it. An example when Activity.OnPause is called and not Activity.OnSaveInstanceState(Android.OS.Bundle) is when activity B is launched in front of activity A: the system may avoid calling Activity.OnSaveInstanceState(Android.OS.Bundle) on activity A if it isn't killed during the lifetime of B since the state of the user interface of A will stay intact.

The default implementation takes care of most of the UI per-instance state for you by calling Android.Views.View.OnSaveInstanceState on each view in the hierarchy that has an id, and by saving the id of the currently focused view (all of which is restored by the default implementation of Activity.OnRestoreInstanceState(Android.OS.Bundle)). If you override this method to save additional information not captured by each individual view, you will likely want to call through to the default implementation, otherwise be prepared to save all of the state of each view yourself.

If called, this method will occur before Activity.OnStop. There are no guarantees about whether it will occur before or after Activity.OnPause.

[Android Documentation]

Requirements

Namespace: Android.App
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1