added in version 22.1.0
belongs to Maven artifact com.android.support:support-fragment:28.0.0-alpha1

Fragment

public class Fragment
extends Object implements ComponentCallbacks, View.OnCreateContextMenuListener, LifecycleOwner, ViewModelStoreOwner

java.lang.Object
   ↳ android.support.v4.app.Fragment
Known Direct Subclasses
Known Indirect Subclasses


Static library support version of the framework's Fragment. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework Fragment documentation for a class overview.

The main differences when using this support version instead of the framework version are:

Summary

Nested classes

class Fragment.InstantiationException

Thrown by instantiate(Context, String, Bundle) when there is an instantiation failure. 

class Fragment.SavedState

State information that has been retrieved from a fragment instance through FragmentManager.saveFragmentInstanceState

Public constructors

Fragment()

Default constructor.

Public methods

void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)

Print the Fragments's state into the given stream.

final boolean equals(Object o)

Subclasses can not override equals().

final FragmentActivity getActivity()

Return the FragmentActivity this fragment is currently associated with.

boolean getAllowEnterTransitionOverlap()

Returns whether the the exit transition and enter transition overlap or not.

boolean getAllowReturnTransitionOverlap()

Returns whether the the return transition and reenter transition overlap or not.

final Bundle getArguments()

Return the arguments supplied when the fragment was instantiated, if any.

final FragmentManager getChildFragmentManager()

Return a private FragmentManager for placing and managing Fragments inside of this Fragment.

Context getContext()

Return the Context this fragment is currently associated with.

Object getEnterTransition()

Returns the Transition that will be used to move Views into the initial scene.

Object getExitTransition()

Returns the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack.

final FragmentManager getFragmentManager()

Return the FragmentManager for interacting with fragments associated with this fragment's activity.

final Object getHost()

Return the host object of this fragment.

final int getId()

Return the identifier this fragment is known by.

final LayoutInflater getLayoutInflater()

Returns the cached LayoutInflater used to inflate Views of this Fragment.

Lifecycle getLifecycle()
LoaderManager getLoaderManager()

Return the LoaderManager for this fragment.

final Fragment getParentFragment()

Returns the parent Fragment containing this Fragment.

Object getReenterTransition()

Returns the Transition that will be used to move Views in to the scene when returning due to popping a back stack.

final Resources getResources()

Return requireActivity().getResources().

final boolean getRetainInstance()
Object getReturnTransition()

Returns the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack.

Object getSharedElementEnterTransition()

Returns the Transition that will be used for shared elements transferred into the content Scene.

Object getSharedElementReturnTransition()

Return the Transition that will be used for shared elements transferred back during a pop of the back stack.

final String getString(int resId, Object... formatArgs)

Return a localized formatted string from the application's package's default string table, substituting the format arguments as defined in Formatter and format(String, Object...).

final String getString(int resId)

Return a localized string from the application's package's default string table.

final String getTag()

Get the tag name of the fragment, if specified.

final Fragment getTargetFragment()

Return the target fragment set by setTargetFragment(Fragment, int).

final int getTargetRequestCode()

Return the target request code set by setTargetFragment(Fragment, int).

final CharSequence getText(int resId)

Return a localized, styled CharSequence from the application's package's default string table.

boolean getUserVisibleHint()
View getView()

Get the root view for the fragment's layout (the one returned by onCreateView(LayoutInflater, ViewGroup, Bundle)), if provided.

ViewModelStore getViewModelStore()
final int hashCode()

Subclasses can not override hashCode().

static Fragment instantiate(Context context, String fname)

Like instantiate(Context, String, Bundle) but with a null argument Bundle.

static Fragment instantiate(Context context, String fname, Bundle args)

Create a new instance of a Fragment with the given class name.

final boolean isAdded()

Return true if the fragment is currently added to its activity.

final boolean isDetached()

Return true if the fragment has been explicitly detached from the UI.

final boolean isHidden()

Return true if the fragment has been hidden.

final boolean isInLayout()

Return true if the layout is included as part of an activity view hierarchy via the <fragment> tag.

final boolean isRemoving()

Return true if this fragment is currently being removed from its activity.

final boolean isResumed()

Return true if the fragment is in the resumed state.

final boolean isStateSaved()

Returns true if this fragment is added and its state has already been saved by its host.

final boolean isVisible()

Return true if the fragment is currently visible to the user.

void onActivityCreated(Bundle savedInstanceState)

Called when the fragment's activity has been created and this fragment's view hierarchy instantiated.

void onActivityResult(int requestCode, int resultCode, Intent data)

Receive the result from a previous call to startActivityForResult(Intent, int).

void onAttach(Activity activity)

This method was deprecated in API level 24.1.0. See onAttach(Context).

void onAttach(Context context)

Called when a fragment is first attached to its context.

void onAttachFragment(Fragment childFragment)

Called when a fragment is attached as a child of this fragment.

void onConfigurationChanged(Configuration newConfig)
boolean onContextItemSelected(MenuItem item)

This hook is called whenever an item in a context menu is selected.

void onCreate(Bundle savedInstanceState)

Called to do initial creation of a fragment.

Animation onCreateAnimation(int transit, boolean enter, int nextAnim)

Called when a fragment loads an animation.

Animator onCreateAnimator(int transit, boolean enter, int nextAnim)

Called when a fragment loads an animator.

void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)

Called when a context menu for the view is about to be shown.

void onCreateOptionsMenu(Menu menu, MenuInflater inflater)

Initialize the contents of the Fragment host's standard options menu.

View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

Called to have the fragment instantiate its user interface view.

void onDestroy()

Called when the fragment is no longer in use.

void onDestroyOptionsMenu()

Called when this fragment's option menu items are no longer being included in the overall options menu.

void onDestroyView()

Called when the view previously created by onCreateView(LayoutInflater, ViewGroup, Bundle) has been detached from the fragment.

void onDetach()

Called when the fragment is no longer attached to its activity.

LayoutInflater onGetLayoutInflater(Bundle savedInstanceState)

Returns the LayoutInflater used to inflate Views of this Fragment.

void onHiddenChanged(boolean hidden)

Called when the hidden state (as returned by isHidden() of the fragment has changed.

void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState)

This method was deprecated in API level 24.1.0. See onInflate(Context, AttributeSet, Bundle).

void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState)

Called when a fragment is being created as part of a view layout inflation, typically from setting the content view of an activity.

void onLowMemory()
void onMultiWindowModeChanged(boolean isInMultiWindowMode)

Called when the Fragment's activity changes from fullscreen mode to multi-window mode and visa-versa.

boolean onOptionsItemSelected(MenuItem item)

This hook is called whenever an item in your options menu is selected.

void onOptionsMenuClosed(Menu menu)

This hook is called whenever the options menu is being closed (either by the user canceling the menu with the back/menu button, or when an item is selected).

void onPause()

Called when the Fragment is no longer resumed.

void onPictureInPictureModeChanged(boolean isInPictureInPictureMode)

Called by the system when the activity changes to and from picture-in-picture mode.

void onPrepareOptionsMenu(Menu menu)

Prepare the Fragment host's standard options menu to be displayed.

void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)

Callback for the result from requesting permissions.

void onResume()

Called when the fragment is visible to the user and actively running.

void onSaveInstanceState(Bundle outState)

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.

void onStart()

Called when the Fragment is visible to the user.

void onStop()

Called when the Fragment is no longer started.

void onViewCreated(View view, Bundle savedInstanceState)

Called immediately after onCreateView(LayoutInflater, ViewGroup, Bundle) has returned, but before any saved state has been restored in to the view.

void onViewStateRestored(Bundle savedInstanceState)

Called when all saved state has been restored into the view hierarchy of the fragment.

void postponeEnterTransition()

Postpone the entering Fragment transition until startPostponedEnterTransition() or executePendingTransactions() has been called.

void registerForContextMenu(View view)

Registers a context menu to be shown for the given view (multiple views can show the context menu).

final void requestPermissions(String[] permissions, int requestCode)

Requests permissions to be granted to this application.

final FragmentActivity requireActivity()

Return the FragmentActivity this fragment is currently associated with.

final Context requireContext()

Return the Context this fragment is currently associated with.

final FragmentManager requireFragmentManager()

Return the FragmentManager for interacting with fragments associated with this fragment's activity.

final Object requireHost()

Return the host object of this fragment.

void setAllowEnterTransitionOverlap(boolean allow)

Sets whether the the exit transition and enter transition overlap or not.

void setAllowReturnTransitionOverlap(boolean allow)

Sets whether the the return transition and reenter transition overlap or not.

void setArguments(Bundle args)

Supply the construction arguments for this fragment.

void setEnterSharedElementCallback(SharedElementCallback callback)

When custom transitions are used with Fragments, the enter transition callback is called when this Fragment is attached or detached when not popping the back stack.

void setEnterTransition(Object transition)

Sets the Transition that will be used to move Views into the initial scene.

void setExitSharedElementCallback(SharedElementCallback callback)

When custom transitions are used with Fragments, the exit transition callback is called when this Fragment is attached or detached when popping the back stack.

void setExitTransition(Object transition)

Sets the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack.

void setHasOptionsMenu(boolean hasMenu)

Report that this fragment would like to participate in populating the options menu by receiving a call to onCreateOptionsMenu(Menu, MenuInflater) and related methods.

void setInitialSavedState(Fragment.SavedState state)

Set the initial saved state that this Fragment should restore itself from when first being constructed, as returned by FragmentManager.saveFragmentInstanceState.

void setMenuVisibility(boolean menuVisible)

Set a hint for whether this fragment's menu should be visible.

void setReenterTransition(Object transition)

Sets the Transition that will be used to move Views in to the scene when returning due to popping a back stack.

void setRetainInstance(boolean retain)

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

void setReturnTransition(Object transition)

Sets the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack.

void setSharedElementEnterTransition(Object transition)

Sets the Transition that will be used for shared elements transferred into the content Scene.

void setSharedElementReturnTransition(Object transition)

Sets the Transition that will be used for shared elements transferred back during a pop of the back stack.

void setTargetFragment(Fragment fragment, int requestCode)

Optional target for this fragment.

void setUserVisibleHint(boolean isVisibleToUser)

Set a hint to the system about whether this fragment's UI is currently visible to the user.

boolean shouldShowRequestPermissionRationale(String permission)

Gets whether you should show UI with rationale for requesting a permission.

void startActivity(Intent intent)

Call startActivity(Intent) from the fragment's containing Activity.

void startActivity(Intent intent, Bundle options)

Call startActivity(Intent, Bundle) from the fragment's containing Activity.

void startActivityForResult(Intent intent, int requestCode)

Call startActivityForResult(Intent, int) from the fragment's containing Activity.

void startActivityForResult(Intent intent, int requestCode, Bundle options)

Call startActivityForResult(Intent, int, Bundle) from the fragment's containing Activity.

void startIntentSenderForResult(IntentSender intent, int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options)

Call startIntentSenderForResult(IntentSender, int, Intent, int, int, int, Bundle) from the fragment's containing Activity.

void startPostponedEnterTransition()

Begin postponed transitions after postponeEnterTransition() was called.

String toString()
void unregisterForContextMenu(View view)

Prevents a context menu to be shown for the given view.

Inherited methods

From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.view.View.OnCreateContextMenuListener
From interface android.arch.lifecycle.LifecycleOwner
From interface android.arch.lifecycle.ViewModelStoreOwner

Public constructors

Fragment

added in version 22.1.0
Fragment ()

Default constructor. Every fragment must have an empty constructor, so it can be instantiated when restoring its activity's state. It is strongly recommended that subclasses do not have other constructors with parameters, since these constructors will not be called when the fragment is re-instantiated; instead, arguments can be supplied by the caller with setArguments(Bundle) and later retrieved by the Fragment with getArguments().

Applications should generally not implement a constructor. Prefer onAttach(Context) instead. It is the first place application code can run where the fragment is ready to be used - the point where the fragment is actually associated with its context. Some applications may also want to implement onInflate(Activity, AttributeSet, Bundle) to retrieve attributes from a layout resource, although note this happens when the fragment is attached.

Public methods

dump

added in version 22.1.0
void dump (String prefix, 
                FileDescriptor fd, 
                PrintWriter writer, 
                String[] args)

Print the Fragments's state into the given stream.

Parameters
prefix String: Text to print at the front of each line.

fd FileDescriptor: The raw file descriptor that the dump is being sent to.

writer PrintWriter: The PrintWriter to which you should dump your state. This will be closed for you after you return.

args String: additional arguments to the dump request.

equals

added in version 22.1.0
boolean equals (Object o)

Subclasses can not override equals().

Parameters
o Object

Returns
boolean

getActivity

added in version 22.1.0
FragmentActivity getActivity ()

Return the FragmentActivity this fragment is currently associated with. May return null if the fragment is associated with a Context instead.

Returns
FragmentActivity

See also:

getAllowEnterTransitionOverlap

added in version 22.1.0
boolean getAllowEnterTransitionOverlap ()

Returns whether the the exit transition and enter transition overlap or not. When true, the enter transition will start as soon as possible. When false, the enter transition will wait until the exit transition completes before starting.

Returns
boolean true when the enter transition should start as soon as possible or false to when it should wait until the exiting transition completes.

getAllowReturnTransitionOverlap

added in version 22.1.0
boolean getAllowReturnTransitionOverlap ()

Returns whether the the return transition and reenter transition overlap or not. When true, the reenter transition will start as soon as possible. When false, the reenter transition will wait until the return transition completes before starting.

Returns
boolean true to start the reenter transition when possible or false to wait until the return transition completes.

getArguments

added in version 22.1.0
Bundle getArguments ()

Return the arguments supplied when the fragment was instantiated, if any.

Returns
Bundle

getChildFragmentManager

added in version 22.1.0
FragmentManager getChildFragmentManager ()

Return a private FragmentManager for placing and managing Fragments inside of this Fragment.

Returns
FragmentManager

getContext

added in version 24.1.0
Context getContext ()

Return the Context this fragment is currently associated with.

Returns
Context

See also:

getEnterTransition

added in version 22.1.0
Object getEnterTransition ()

Returns the Transition that will be used to move Views into the initial scene. The entering Views will be those that are regular Views or ViewGroups that have isTransitionGroup() return true. Typical Transitions will extend Visibility as entering is governed by changing visibility from INVISIBLE to VISIBLE.

Returns
Object the Transition to use to move Views into the initial Scene.

getExitTransition

added in version 22.1.0
Object getExitTransition ()

Returns the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack. The exiting Views will be those that are regular Views or ViewGroups that have isTransitionGroup() return true. Typical Transitions will extend Visibility as exiting is governed by changing visibility from VISIBLE to INVISIBLE. If transition is null, the views will remain unaffected.

Returns
Object the Transition to use to move Views out of the Scene when the Fragment is being closed not due to popping the back stack.

getFragmentManager

added in version 22.1.0
FragmentManager getFragmentManager ()

Return the FragmentManager for interacting with fragments associated with this fragment's activity. Note that this will be non-null slightly before getActivity(), during the time from when the fragment is placed in a FragmentTransaction until it is committed and attached to its activity.

If this Fragment is a child of another Fragment, the FragmentManager returned here will be the parent's getChildFragmentManager().

Returns
FragmentManager

getHost

added in version 24.1.0
Object getHost ()

Return the host object of this fragment. May return null if the fragment isn't currently being hosted.

Returns
Object

See also:

getId

added in version 22.1.0
int getId ()

Return the identifier this fragment is known by. This is either the android:id value supplied in a layout or the container view ID supplied when adding the fragment.

Returns
int

getLayoutInflater

added in version 25.4.0
LayoutInflater getLayoutInflater ()

Returns the cached LayoutInflater used to inflate Views of this Fragment. If onGetLayoutInflater(Bundle) has not been called onGetLayoutInflater(Bundle) will be called with a null argument and that value will be cached.

The cached LayoutInflater will be replaced immediately prior to onCreateView(LayoutInflater, ViewGroup, Bundle) and cleared immediately after onDetach().

Returns
LayoutInflater The LayoutInflater used to inflate Views of this Fragment.

getLifecycle

added in version 26.1.0
Lifecycle getLifecycle ()

Returns
Lifecycle

getLoaderManager

added in version 22.1.0
LoaderManager getLoaderManager ()

Return the LoaderManager for this fragment.

Returns
LoaderManager

getParentFragment

added in version 22.1.0
Fragment getParentFragment ()

Returns the parent Fragment containing this Fragment. If this Fragment is attached directly to an Activity, returns null.

Returns
Fragment

getReenterTransition

added in version 22.1.0
Object getReenterTransition ()

Returns the Transition that will be used to move Views in to the scene when returning due to popping a back stack. The entering Views will be those that are regular Views or ViewGroups that have isTransitionGroup() return true. Typical Transitions will extend Visibility as exiting is governed by changing visibility from VISIBLE to INVISIBLE. If transition is null, the views will remain unaffected. If nothing is set, the default will be to use the same transition as setExitTransition(Object).

Returns
Object the Transition to use to move Views into the scene when reentering from a previously-started Activity.

getResources

added in version 22.1.0
Resources getResources ()

Return requireActivity().getResources().

Returns
Resources

getRetainInstance

added in version 22.1.0
boolean getRetainInstance ()

Returns
boolean

getReturnTransition

added in version 22.1.0
Object getReturnTransition ()

Returns the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack. The exiting Views will be those that are regular Views or ViewGroups that have isTransitionGroup() return true. Typical Transitions will extend Visibility as entering is governed by changing visibility from VISIBLE to INVISIBLE. If transition is null, entering Views will remain unaffected.

Returns
Object the Transition to use to move Views out of the Scene when the Fragment is preparing to close.

getSharedElementEnterTransition

added in version 22.1.0
Object getSharedElementEnterTransition ()

Returns the Transition that will be used for shared elements transferred into the content Scene. Typical Transitions will affect size and location, such as ChangeBounds. A null value will cause transferred shared elements to blink to the final position.

Returns
Object The Transition to use for shared elements transferred into the content Scene.

getSharedElementReturnTransition

added in version 22.1.0
Object getSharedElementReturnTransition ()

Return the Transition that will be used for shared elements transferred back during a pop of the back stack. This Transition acts in the leaving Fragment. Typical Transitions will affect size and location, such as ChangeBounds. A null value will cause transferred shared elements to blink to the final position. If no value is set, the default will be to use the same value as setSharedElementEnterTransition(Object).

Returns
Object The Transition to use for shared elements transferred out of the content Scene.

getString

added in version 22.1.0
String getString (int resId, 
                Object... formatArgs)

Return a localized formatted string from the application's package's default string table, substituting the format arguments as defined in Formatter and format(String, Object...).

Parameters
resId int: Resource id for the format string

formatArgs Object: The format arguments that will be used for substitution.

Returns
String

getString

added in version 22.1.0
String getString (int resId)

Return a localized string from the application's package's default string table.

Parameters
resId int: Resource id for the string

Returns
String

getTag

added in version 22.1.0
String getTag ()

Get the tag name of the fragment, if specified.

Returns
String

getTargetFragment

added in version 22.1.0
Fragment getTargetFragment ()

Return the target fragment set by setTargetFragment(Fragment, int).

Returns
Fragment

getTargetRequestCode

added in version 22.1.0
int getTargetRequestCode ()

Return the target request code set by setTargetFragment(Fragment, int).

Returns
int

getText

added in version 22.1.0
CharSequence getText (int resId)

Return a localized, styled CharSequence from the application's package's default string table.

Parameters
resId int: Resource id for the CharSequence text

Returns
CharSequence

getUserVisibleHint

added in version 22.1.0
boolean getUserVisibleHint ()

Returns
boolean The current value of the user-visible hint on this fragment.

getView

added in version 22.1.0
View getView ()

Get the root view for the fragment's layout (the one returned by onCreateView(LayoutInflater, ViewGroup, Bundle)), if provided.

Returns
View The fragment's root view, or null if it has no layout.

getViewModelStore

added in version 27.1.0
ViewModelStore getViewModelStore ()

Returns
ViewModelStore

hashCode

added in version 22.1.0
int hashCode ()

Subclasses can not override hashCode().

Returns
int

instantiate

added in version 22.1.0
Fragment instantiate (Context context,
                String fname)

Like instantiate(Context, String, Bundle) but with a null argument Bundle.

Parameters
context Context

fname String

Returns
Fragment

instantiate

added in version 22.1.0
Fragment instantiate (Context context,
                String fname, 
                Bundle args)

Create a new instance of a Fragment with the given class name. This is the same as calling its empty constructor.

Parameters
context Context: The calling context being used to instantiate the fragment. This is currently just used to get its ClassLoader.

fname String: The class name of the fragment to instantiate.

args Bundle: Bundle of arguments to supply to the fragment, which it can retrieve with getArguments(). May be null.

Returns
Fragment Returns a new fragment instance.

Throws
InstantiationException If there is a failure in instantiating the given fragment class. This is a runtime exception; it is not normally expected to happen.

isAdded

added in version 22.1.0
boolean isAdded ()

Return true if the fragment is currently added to its activity.

Returns
boolean

isDetached

added in version 22.1.0
boolean isDetached ()

Return true if the fragment has been explicitly detached from the UI. That is, FragmentTransaction.detach(Fragment) has been used on it.

Returns
boolean

isHidden

added in version 22.1.0
boolean isHidden ()

Return true if the fragment has been hidden. By default fragments are shown. You can find out about changes to this state with onHiddenChanged(boolean). Note that the hidden state is orthogonal to other states -- that is, to be visible to the user, a fragment must be both started and not hidden.

Returns
boolean

isInLayout

added in version 22.1.0
boolean isInLayout ()

Return true if the layout is included as part of an activity view hierarchy via the <fragment> tag. This will always be true when fragments are created through the <fragment> tag, except in the case where an old fragment is restored from a previous state and it does not appear in the layout of the current state.

Returns
boolean

isRemoving

added in version 22.1.0
boolean isRemoving ()

Return true if this fragment is currently being removed from its activity. This is not whether its activity is finishing, but rather whether it is in the process of being removed from its activity.

Returns
boolean

isResumed

added in version 22.1.0
boolean isResumed ()

Return true if the fragment is in the resumed state. This is true for the duration of onResume() and onPause() as well.

Returns
boolean

isStateSaved

added in version 26.1.0
boolean isStateSaved ()

Returns true if this fragment is added and its state has already been saved by its host. Any operations that would change saved state should not be performed if this method returns true, and some operations such as setArguments(Bundle) will fail.

Returns
boolean true if this fragment's state has already been saved by its host

isVisible

added in version 22.1.0
boolean isVisible ()

Return true if the fragment is currently visible to the user. This means it: (1) has been added, (2) has its view attached to the window, and (3) is not hidden.

Returns
boolean

onActivityCreated

added in version 22.1.0
void onActivityCreated (Bundle savedInstanceState)

Called when the fragment's activity has been created and this fragment's view hierarchy instantiated. It can be used to do final initialization once these pieces are in place, such as retrieving views or restoring state. It is also useful for fragments that use setRetainInstance(boolean) to retain their instance, as this callback tells the fragment when it is fully associated with the new activity instance. This is called after onCreateView(LayoutInflater, ViewGroup, Bundle) and before onViewStateRestored(Bundle).

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

onActivityResult

added in version 22.1.0
void onActivityResult (int requestCode, 
                int resultCode, 
                Intent data)

Receive the result from a previous call to startActivityForResult(Intent, int). This follows the related Activity API as described there in onActivityResult(int, int, Intent).

Parameters
requestCode int: The integer request code originally supplied to startActivityForResult(), allowing you to identify who this result came from.

resultCode int: The integer result code returned by the child activity through its setResult().

data Intent: An Intent, which can return result data to the caller (various data can be attached to Intent "extras").

onAttach

added in version 22.1.0
void onAttach (Activity activity)

This method was deprecated in API level 24.1.0.
See onAttach(Context).

Called when a fragment is first attached to its activity. onCreate(Bundle) will be called after this.

Parameters
activity Activity

onAttach

added in version 24.1.0
void onAttach (Context context)

Called when a fragment is first attached to its context. onCreate(Bundle) will be called after this.

Parameters
context Context

onAttachFragment

added in version 24.1.0
void onAttachFragment (Fragment childFragment)

Called when a fragment is attached as a child of this fragment.

This is called after the attached fragment's onAttach and before the attached fragment's onCreate if the fragment has not yet had a previous call to onCreate.

Parameters
childFragment Fragment: child fragment being attached

onConfigurationChanged

added in version 22.1.0
void onConfigurationChanged (Configuration newConfig)

Parameters
newConfig Configuration

onContextItemSelected

added in version 22.1.0
boolean onContextItemSelected (MenuItem item)

This hook is called whenever an item in a context menu is selected. The default implementation simply returns false to have the normal processing happen (calling the item's Runnable or sending a message to its Handler as appropriate). You can use this method for any items for which you would like to do processing without those other facilities.

Use getMenuInfo() to get extra information set by the View that added this menu item.

Derived classes should call through to the base class for it to perform the default menu handling.

Parameters
item MenuItem: The context menu item that was selected.

Returns
boolean boolean Return false to allow normal context menu processing to proceed, true to consume it here.

onCreate

added in version 22.1.0
void onCreate (Bundle savedInstanceState)

Called to do initial creation of a fragment. This is called after onAttach(Activity) and before onCreateView(LayoutInflater, ViewGroup, Bundle).

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).

Any restored child fragments will be created before the base Fragment.onCreate method returns.

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

onCreateAnimation

added in version 22.1.0
Animation onCreateAnimation (int transit,
                boolean enter, 
                int nextAnim)

Called when a fragment loads an animation. Note that if setCustomAnimations(int, int) was called with Animator resources instead of Animation resources, nextAnim will be an animator resource.

Parameters
transit int: The value set in setTransition(int) or 0 if not set.

enter boolean: true when the fragment is added/attached/shown or false when the fragment is removed/detached/hidden.

nextAnim int: The resource set in setCustomAnimations(int, int), setCustomAnimations(int, int, int, int), or 0 if neither was called. The value will depend on the current operation.

Returns
Animation

onCreateAnimator

added in version 26.1.0
Animator onCreateAnimator (int transit,
                boolean enter, 
                int nextAnim)

Called when a fragment loads an animator. This will be called when onCreateAnimation(int, boolean, int) returns null. Note that if setCustomAnimations(int, int) was called with Animation resources instead of Animator resources, nextAnim will be an animation resource.

Parameters
transit int: The value set in setTransition(int) or 0 if not set.

enter boolean: true when the fragment is added/attached/shown or false when the fragment is removed/detached/hidden.

nextAnim int: The resource set in setCustomAnimations(int, int), setCustomAnimations(int, int, int, int), or 0 if neither was called. The value will depend on the current operation.

Returns
Animator

onCreateContextMenu

added in version 22.1.0
void onCreateContextMenu (ContextMenu menu,
                View v,