Fragment.OnCreate(Bundle) Method

Definition

Called to do initial creation of a fragment.

[Android.Runtime.Register("onCreate", "(Landroid/os/Bundle;)V", "GetOnCreate_Landroid_os_Bundle_Handler")]
public virtual void OnCreate (Android.OS.Bundle? savedInstanceState);
[<Android.Runtime.Register("onCreate", "(Landroid/os/Bundle;)V", "GetOnCreate_Landroid_os_Bundle_Handler")>]
abstract member OnCreate : Android.OS.Bundle -> unit
override this.OnCreate : Android.OS.Bundle -> unit

Parameters

savedInstanceState
Bundle

If the fragment is being re-created from a previous saved state, this is the state.

Attributes

Remarks

Called to do initial creation of a fragment. This is called after #onAttach(Activity) and before #onCreateView(LayoutInflater, ViewGroup, Bundle), but is not called if the fragment instance is retained across Activity re-creation (see #setRetainInstance(boolean)).

Note that this can be called while the fragment's activity is still in the process of being created. As such, you can not rely on things like the activity's content view hierarchy being initialized at this point. If you want to do work once the activity itself is created, see #onActivityCreated(Bundle).

If your app's targetSdkVersion is android.os.Build.VERSION_CODES#M or lower, child fragments being restored from the savedInstanceState are restored after onCreate returns. When targeting android.os.Build.VERSION_CODES#N or above and running on an N or newer platform version they are restored by Fragment.onCreate.

Java documentation for android.app.Fragment.onCreate(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