FragmentHostCallback

abstract class FragmentHostCallback<H : Any?> : FragmentContainer


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
<H : Any?>

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

Summary

Public constructors

<H : Any?> FragmentHostCallback(
    context: Context,
    handler: Handler,
    windowAnimations: Int
)

Public functions

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

Print internal state into the given stream.

open View?

Return the view with the given resource ID.

abstract H

Return the object that's currently hosting the fragment.

open LayoutInflater

Return a LayoutInflater.

open Int

Return the window animations.

open Boolean

Return true if the container holds any view.

open Boolean

Return true if there are window animations.

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

This function is deprecated. Have your FragmentHostCallback implement {@link ActivityResultRegistryOwner} to allow Fragments to use {@link Fragment#registerForActivityResult(ActivityResultContract, ActivityResultCallback)} with {@link RequestMultiplePermissions}.

open Boolean

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(
    fragment: Fragment,
    intent: Intent,
    requestCode: Int
)

Starts a new Activity from the given fragment.

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

Starts a new Activity from the given fragment.

open 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 {@link ActivityResultRegistryOwner} to allow Fragments to use {@link Fragment#registerForActivityResult(ActivityResultContract, ActivityResultCallback)} with {@link StartIntentSenderForResult}.

open Unit

Invalidates the activity's options menu.

Inherited functions

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

This function is deprecated.

Use setFragmentFactory to control how Fragments are instantiated.

Public constructors

FragmentHostCallback

<H : Any?> FragmentHostCallback(
    context: Context,
    handler: Handler,
    windowAnimations: Int
)

Public functions

onDump

Added in 1.1.0
open 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

Added in 1.7.0-beta01
open 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

Added in 1.1.0
abstract fun onGetHost(): H

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

Added in 1.1.0
open fun onGetLayoutInflater(): LayoutInflater

Return a LayoutInflater. See Activity.getLayoutInflater.

onGetWindowAnimations

Added in 1.1.0
open fun onGetWindowAnimations(): Int

Return the window animations.

onHasView

Added in 1.7.0-beta01
open fun onHasView(): Boolean

Return true if the container holds any view.

onHasWindowAnimations

Added in 1.1.0
open fun onHasWindowAnimations(): Boolean

Return true if there are window animations.

onRequestPermissionsFromFragment

Added in 1.1.0
Deprecated in 1.3.0
open fun onRequestPermissionsFromFragment(
    fragment: Fragment,
    permissions: Array<String>,
    requestCode: Int
): Unit

Requests permissions from the given fragment. See FragmentActivity.requestPermissions

onShouldSaveFragmentState

Added in 1.1.0
open fun onShouldSaveFragmentState(fragment: Fragment): Boolean

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

onShouldShowRequestPermissionRationale

Added in 1.1.0
open fun onShouldShowRequestPermissionRationale(permission: String): Boolean

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

onStartActivityFromFragment

Added in 1.1.0
open fun onStartActivityFromFragment(
    fragment: Fragment,
    intent: Intent,
    requestCode: Int
): Unit

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

onStartActivityFromFragment

Added in 1.1.0
open fun onStartActivityFromFragment(
    fragment: Fragment,
    intent: Intent,
    requestCode: Int,
    options: Bundle?
): Unit

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

onStartIntentSenderFromFragment

Added in 1.1.0
Deprecated in 1.3.0
open 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 Activity.startIntentSender.

onSupportInvalidateOptionsMenu

Added in 1.1.0
open fun onSupportInvalidateOptionsMenu(): Unit

Invalidates the activity's options menu. See FragmentActivity.supportInvalidateOptionsMenu