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

FragmentHostCallback

abstract class FragmentHostCallback<E : Any!> : FragmentContainer
kotlin.Any
   ↳ androidx.fragment.app.FragmentContainer
   ↳ androidx.fragment.app.FragmentHostCallback

Integration points with the Fragment host.

Fragments may be hosted by any object; such as an Activity. In order to host fragments, implement FragmentHostCallback, overriding the methods applicable to the host.

FragmentManager changes its behavior based on what optional interfaces your FragmentHostCallback implements. This includes the following:

Summary

Public constructors
<init>(@NonNull context: Context, @NonNull handler: Handler, windowAnimations: Int)

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

Print internal state into the given stream.

open View?

abstract E?

Return the object that's currently hosting the fragment.

open LayoutInflater

Return a LayoutInflater.

open Int

Return the window animations.

open Boolean

open Boolean

Return true if there are window animations.

open Unit
onRequestPermissionsFromFragment(@NonNull fragment: Fragment, @NonNull permissions: Array<String!>, requestCode: Int)

Requests permissions from the given fragment.

open Boolean
onShouldSaveFragmentState(@NonNull fragment: Fragment)

Return true if the fragment's state needs to be saved.

open Boolean

Checks whether to show permission rationale UI from a fragment.

open Unit
onStartActivityFromFragment(@NonNull fragment: Fragment, intent: Intent!, requestCode: Int)

Starts a new Activity from the given fragment.

open Unit
onStartActivityFromFragment(@NonNull fragment: Fragment, intent: Intent!, requestCode: Int, @Nullable options: Bundle?)

Starts a new Activity from the given fragment.

open Unit
onStartIntentSenderFromFragment(@NonNull fragment: Fragment, intent: IntentSender!, requestCode: Int, @Nullable fillInIntent: Intent?, flagsMask: Int, flagsValues: Int, extraFlags: Int, @Nullable options: Bundle?)

Starts a new IntentSender from the given fragment.

open Unit

Invalidates the activity's options menu.

Inherited functions

Public constructors

<init>

FragmentHostCallback(
    @NonNull context: Context,
    @NonNull handler: Handler,
    windowAnimations: Int)

Public methods

onDump

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

Print internal state into the given stream.

Parameters
prefix String: Desired prefix to prepend at each line of output.
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 Array<String!>?: additional arguments to the dump request.

onFindViewById

@Nullable open fun onFindViewById(id: Int): View?

onGetHost

@Nullable abstract fun onGetHost(): E?

Return the object that's currently hosting the fragment. If a Fragment is hosted by a FragmentActivity, the object returned here should be the same object returned from Fragment#getActivity().

onGetLayoutInflater

@NonNull open fun onGetLayoutInflater(): LayoutInflater

Return a LayoutInflater. See Activity#getLayoutInflater().

onGetWindowAnimations

open fun onGetWindowAnimations(): Int

Return the window animations.

onHasView

open fun onHasView(): Boolean

onHasWindowAnimations

open fun onHasWindowAnimations(): Boolean

Return true if there are window animations.

onRequestPermissionsFromFragment

open fun onRequestPermissionsFromFragment(
    @NonNull fragment: Fragment,
    @NonNull permissions: Array<String!>,
    requestCode: Int
): Unit

Deprecated: Have your FragmentHostCallback implement ActivityResultRegistryOwner to allow Fragments to use Fragment#registerForActivityResult(ActivityResultContract, ActivityResultCallback) with RequestMultiplePermissions. This method will still be called when Fragments call the deprecated requestPermissions() method.

Requests permissions from the given fragment. See FragmentActivity#requestPermissions(String[], int)

onShouldSaveFragmentState

open fun onShouldSaveFragmentState(@NonNull fragment: Fragment): Boolean

Return true if the fragment's state needs to be saved.

onShouldShowRequestPermissionRationale

open fun onShouldShowRequestPermissionRationale(@NonNull permission: String): Boolean

Checks whether to show permission rationale UI from a fragment. See FragmentActivity#shouldShowRequestPermissionRationale(String)

onStartActivityFromFragment

open fun onStartActivityFromFragment(
    @NonNull fragment: Fragment,
    intent: Intent!,
    requestCode: Int
): Unit

Starts a new Activity from the given fragment. See FragmentActivity#startActivityForResult(Intent, int).

onStartActivityFromFragment

open fun onStartActivityFromFragment(
    @NonNull fragment: Fragment,
    intent: Intent!,
    requestCode: Int,
    @Nullable options: Bundle?
): Unit

Starts a new Activity from the given fragment. See FragmentActivity#startActivityForResult(Intent, int, Bundle).

onStartIntentSenderFromFragment

open fun onStartIntentSenderFromFragment(
    @NonNull fragment: Fragment,
    intent: IntentSender!,
    requestCode: Int,
    @Nullable fillInIntent: Intent?,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int,
    @Nullable options: Bundle?
): Unit

Deprecated: Have your FragmentHostCallback implement ActivityResultRegistryOwner to allow Fragments to use Fragment#registerForActivityResult(ActivityResultContract, ActivityResultCallback) with StartIntentSenderForResult. This method will still be called when Fragments call the deprecated startIntentSenderForResult() method.

Starts a new IntentSender from the given fragment. See Activity#startIntentSender(IntentSender, Intent, int, int, int, Bundle).

onSupportInvalidateOptionsMenu

open fun onSupportInvalidateOptionsMenu(): Unit

Invalidates the activity's options menu. See FragmentActivity#supportInvalidateOptionsMenu()