Google is committed to advancing racial equity for Black communities. See how.

Fragment

open class Fragment : ComponentCallbacks, OnCreateContextMenuListener, LifecycleOwner, ViewModelStoreOwner, HasDefaultViewModelProviderFactory, SavedStateRegistryOwner, ActivityResultCaller
kotlin.Any
   ↳ androidx.fragment.app.Fragment

Static library support version of the framework's android.app.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 android.app.Fragment documentation for a class overview.

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

Summary

Nested classes
open

Thrown by FragmentFactory#instantiate(ClassLoader, String) when there is an instantiation failure.

open

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

Public constructors

Constructor used by the default FragmentFactory.

<init>(@LayoutRes contentLayoutId: Int)

Alternate constructor that can be called from your default, no argument constructor to provide a default layout that will be inflated by onCreateView(LayoutInflater, ViewGroup, Bundle).

Public methods
open Unit
dump(@NonNull prefix: String, @Nullable fd: FileDescriptor?, @NonNull writer: PrintWriter, @Nullable args: Array<String!>?)

Print the Fragments's state into the given stream.

Boolean
equals(@Nullable other: Any?)

Subclasses can not override equals().

FragmentActivity?

Return the FragmentActivity this fragment is currently associated with.

open Boolean

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

open Boolean

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

Bundle?

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

FragmentManager

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

open Context?

Return the Context this fragment is currently associated with.

open ViewModelProvider.Factory

Returns the default ViewModelProvider.Factory that should be used when no custom Factory is provided to the ViewModelProvider constructors.

open Any?

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

open Any?

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.

FragmentManager?

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

Any?

Return the host object of this fragment.

Int

Return the identifier this fragment is known by.

LayoutInflater

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

open Lifecycle

Returns the Lifecycle of the provider.

open LoaderManager

Return the LoaderManager for this fragment.

Fragment?

Returns the parent Fragment containing this Fragment.

FragmentManager

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

open Any?

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

Resources

Return requireActivity().getResources().

Boolean

Returns true if this fragment instance's state will be retained across configuration changes, and false if it will not.

open Any?

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.

SavedStateRegistry

open Any?