共用方式為


Activity.LastNonConfigurationInstance Property

Definition

Retrieve the non-configuration instance data that was previously returned by #onRetainNonConfigurationInstance().

public virtual Java.Lang.Object? LastNonConfigurationInstance { [Android.Runtime.Register("getLastNonConfigurationInstance", "()Ljava/lang/Object;", "GetGetLastNonConfigurationInstanceHandler")] get; }
[<get: Android.Runtime.Register("getLastNonConfigurationInstance", "()Ljava/lang/Object;", "GetGetLastNonConfigurationInstanceHandler")>]
member this.LastNonConfigurationInstance : Java.Lang.Object

Property Value

the object previously returned by #onRetainNonConfigurationInstance()

Attributes

Remarks

Retrieve the non-configuration instance data that was previously returned by #onRetainNonConfigurationInstance(). This will be available from the initial #onCreate and #onStart calls to the new instance, allowing you to extract any useful dynamic state from the previous instance.

Note that the data you retrieve here should <em>only</em> be used as an optimization for handling configuration changes. You should always be able to handle getting a null pointer back, and an activity must still be able to restore itself to its previous state (through the normal #onSaveInstanceState(Bundle) mechanism) even if this function returns null.

<strong>Note:</strong> For most cases you should use the Fragment API Fragment#setRetainInstance(boolean) instead; this is also available on older platforms through the Android support libraries.

Java documentation for android.app.Activity.getLastNonConfigurationInstance().

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