{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

FragmentHostCallback

abstract class FragmentHostCallback<E> : 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:

Parameters
<E>

the type of object that's currently hosting the fragments. An instance of this class must be returned by onGetHost.

Summary

Public constructors

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

Public functions

Unit
onDump(
    prefix: String,
    fd: FileDescriptor?,
    writer: PrintWriter,
    args: Array<String!>?
)

Print internal state into the given stream.

View?

Return the view with the given resource ID.

abstract E?

Return the object that's currently hosting the fragment.

LayoutInflater

Return a LayoutInflater.

Int

Return the window animations.

Boolean

Return true if the container holds any view.

Boolean

Return true if there are window animations.

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

This function is deprecated.

Have your FragmentHostCallback implement ActivityResultRegistryOwner to allow Fragments to use registerForActivityResult with RequestMultiplePermissions.

Boolean

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

Boolean

Checks whether to show permission rationale UI from a fragment.

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

Starts a new Activity from the given fragment.

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

Starts a new Activity from the given fragment.

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

This function is deprecated.

Have your FragmentHostCallback implement ActivityResultRegistryOwner to allow Fragments to use registerForActivityResult with StartIntentSenderForResult.

Unit

Invalidates the activity's options menu.

Inherited functions

From androidx.fragment.app.FragmentContainer
Fragment
instantiate(context: Context, className: String, arguments: Bundle?)

This function is deprecated.

Use setFragmentFactory to control how Fragments are instantiated.

Public constructors

FragmentHostCallback

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

Public functions

onDump

fun onDump(
    prefix: String,
    fd: FileDescriptor?,
    writer: PrintWriter,
    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

fun onFindViewById(id: Int): View?

Return the view with the given resource ID. May return null if the view is not a child of this container.

onGetHost

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

onGetLayoutInflater

fun onGetLayoutInflater(): LayoutInflater

Return a LayoutInflater. See getLayoutInflater.

onGetWindowAnimations

fun onGetWindowAnimations(): Int

Return the window animations.

onHasView

fun onHasView(): Boolean

Return true if the container holds any view.

onHasWindowAnimations

fun onHasWindowAnimations(): Boolean

Return true if there are window animations.

onRequestPermissionsFromFragment

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

Requests permissions from the given fragment. See requestPermissions

onShouldSaveFragmentState

fun onShouldSaveFragmentState(fragment: Fragment): Boolean

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

onShouldShowRequestPermissionRationale

fun onShouldShowRequestPermissionRationale(permission: String): Boolean

Checks whether to show permission rationale UI from a fragment. See shouldShowRequestPermissionRationale

onStartActivityFromFragment

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

Starts a new Activity from the given fragment. See startActivityForResult.

onStartActivityFromFragment

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

Starts a new Activity from the given fragment. See startActivityForResult.

onStartIntentSenderFromFragment

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

Starts a new IntentSender from the given fragment. See startIntentSender.

Throws
android.content.IntentSender.SendIntentException: android.content.IntentSender.SendIntentException

onSupportInvalidateOptionsMenu

fun onSupportInvalidateOptionsMenu(): Unit

Invalidates the activity's options menu. See supportInvalidateOptionsMenu