public class Fragment implements LifecycleOwner, ViewModelStoreOwner, HasDefaultViewModelProviderFactory, LifecycleOwner, SavedStateRegistryOwner, ActivityResultCaller

Known direct subclasses

A fragment supports adaptive two-pane layout.


The base class for Fragments that handle dynamic feature installation.


Use this as a headless Fragment to add ambient support to an Activity on Wearable devices.


Fragment class for managing search and branding using a view that implements TitleViewAdapter.Provider.


Static library support version of the framework's


A GuidedStepSupportFragment is used to guide the user through a decision or series of decisions.


A fragment that shows DialogPreference, for example or androidx.preference.MultiSelectListPreference.


This fragment provides a container for displaying a LeanbackPreferenceFragmentCompat


Static library support version of the framework's


Media route discovery fragment.


NavHostFragment provides an area within your layout for self-contained navigation to occur.


An OnboardingSupportFragment provides a common and simple way to build onboarding screen for applications.


A fragment for displaying playback controls and related content.


A PreferenceFragmentCompat is the entry point to using the Preference library.


A fragment to handle searches.

Known indirect subclasses

A special version of DialogFragment which uses an AppCompatDialog in place of a platform-styled dialog.


This fragment provides a preference fragment with leanback-style behavior, suitable for embedding into broader UI elements.


Base class for leanback Fragments.


A fragment for creating Leanback browse screens.


The default to display during installation progress.


A fragment for creating Leanback details screens.


The NavHostFragment for dynamic features.


A fragment for displaying an error indication.


Implemented a dialog to input text.


Implemented a dialog to show ListPreference or MultiSelectListPreference.


This fragment provides a fully decorated leanback-style preference fragment, including a list background and header.


Media route chooser dialog fragment.


Media route controller dialog fragment.


Abstract base class which presents a dialog associated with a DialogPreference.


A fragment for creating leanback vertical grids.


Subclass of PlaybackSupportFragment that is responsible for providing a SurfaceView and rendering video.

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

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


Nested types


Thrown by instantiate when there is an instantiation failure.


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

Public constructors

Constructor used by the default FragmentFactory.

Fragment(@LayoutRes @NonNull int contentLayoutId)

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

Public methods

@NonNull void
    @NonNull String prefix,
    @Nullable FileDescriptor fd,
    @NonNull PrintWriter writer,
    @Nullable Array<@NonNull String> args

Print the Fragments's state into the given stream.

final @Override @NonNull boolean

Subclasses can not override equals().

final @Nullable FragmentActivity

Return the FragmentActivity this fragment is currently associated with.

@NonNull boolean

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

@NonNull boolean

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

final @Nullable Bundle

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

final @NonNull FragmentManager

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

@Nullable Context

Return the Context this fragment is currently associated with.

@NonNull @Override ViewModelProvider.Factory

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

@Nullable Object

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

@Nullable Object

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 @Nullable FragmentManager

This method is deprecated.

This has been removed in favor of getParentFragmentManager() which throws an IllegalStateException if the FragmentManager is null.

final @Nullable Object

Return the host object of this fragment.

final @NonNull int

Return the identifier this fragment is known by.

final @NonNull LayoutInflater

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

@Override @NonNull Lifecycle

Returns the Lifecycle of the provider.

@NonNull LoaderManager

This method is deprecated.

Use LoaderManager.getInstance(this).

final @Nullable Fragment

Returns the parent Fragment containing this Fragment.

final @NonNull FragmentManager

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

@Nullable Object

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

final @NonNull Resources

Return requireActivity().getResources().

final @NonNull boolean

This method is deprecated.

Instead of retaining the Fragment itself, use a non-retained Fragment and keep retained state in a ViewModel attached to that Fragment.

@Nullable Object

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.

final @NonNull @Override SavedStateRegistry

Returns owned SavedStateRegistry

@Nullable Object

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

@Nullable Object

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

final @NonNull String

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

final @NonNull String
    @StringRes @NonNull int resId,
    @Nullable Array<@NonNull Object> formatArgs

Return a localized formatted string from the application's package's default string table, substituting the format arguments as defined in java.util.Formatter and format.

final @Nullable String

Get the tag name of the fragment, if specified.

final @Nullable Fragment

This method is deprecated.

Instead of using a target fragment to pass results, use setFragmentResult to deliver results to FragmentResultListener instances registered by other fragments via setFragmentResultListener.

final @NonNull int

This method is deprecated.

When using the target fragment replacement of setFragmentResultListener and setFragmentResult, consider using setArguments to pass a {@code requestKey} if you need to support dynamic request keys.

final @NonNull CharSequence
getText(@StringRes @NonNull int resId)

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

@NonNull boolean

This method is deprecated.

Use setMaxLifecycle instead.

@Nullable View

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

@MainThread @NonNull LifecycleOwner

Get a LifecycleOwner that represents the Fragment's View lifecycle.

@NonNull LiveData<@NonNull LifecycleOwner>

Retrieve a LiveData which allows you to observe the lifecycle of the Fragment's View.

@NonNull @Override ViewModelStore

Returns the ViewModelStore associated with this Fragment

final @Override @NonNull int

Subclasses can not override hashCode().

static @NonNull Fragment

This method is deprecated.

Use getFragmentFactory and instantiate

static @NonNull Fragment
    @NonNull Context context,
    @NonNull String fname,
    @Nullable Bundle args

This method is deprecated.