Fragment

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

Known direct subclasses
AbstractListDetailFragment

A fragment supports adaptive two-pane layout.

AbstractProgressFragment

The base class for Fragments that handle dynamic feature installation.

AmbientModeSupport

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

BrandedSupportFragment

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

DialogFragment

Static library support version of the framework's android.app.DialogFragment.

GuidedStepSupportFragment

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

LeanbackPreferenceDialogFragmentCompat

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

LeanbackSettingsFragmentCompat

This fragment provides a container for displaying a LeanbackPreferenceFragmentCompat

ListFragment

Static library support version of the framework's android.app.ListFragment.

MediaRouteDiscoveryFragment

Media route discovery fragment.

NavHostFragment

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

OnboardingSupportFragment

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

PlaybackSupportFragment

A fragment for displaying playback controls and related content.

PreferenceFragmentCompat

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

SearchSupportFragment

A fragment to handle searches.

Known indirect subclasses
AppCompatDialogFragment

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

BaseLeanbackPreferenceFragmentCompat

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

BaseSupportFragment

Base class for leanback Fragments.

BrowseSupportFragment

A fragment for creating Leanback browse screens.

DefaultProgressFragment

The default androidx.fragment.app.Fragment to display during installation progress.

DetailsSupportFragment

A fragment for creating Leanback details screens.

DynamicNavHostFragment

The NavHostFragment for dynamic features.

EditTextPreferenceDialogFragmentCompat
ErrorSupportFragment

A fragment for displaying an error indication.

LeanbackEditTextPreferenceDialogFragmentCompat

Implemented a dialog to input text.

LeanbackListPreferenceDialogFragmentCompat

Implemented a dialog to show ListPreference or MultiSelectListPreference.

LeanbackPreferenceFragmentCompat

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

ListPreferenceDialogFragmentCompat
MediaRouteChooserDialogFragment

Media route chooser dialog fragment.

MediaRouteControllerDialogFragment

Media route controller dialog fragment.

MultiSelectListPreferenceDialogFragmentCompat
PreferenceDialogFragmentCompat

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

VerticalGridSupportFragment

A fragment for creating leanback vertical grids.

VideoSupportFragment

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


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 types

Fragment.InstantiationException

Thrown by instantiate when there is an instantiation failure.

Fragment.SavedState

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
dump(
    @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
getString(
    @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