FragmentHostCallback

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

Starts a new Activity from the given fragment.

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

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

Added in 1.1.0
FragmentHostCallback(
    context: Context,
    handler: Handler,
    windowAnimations: Int
)

Public functions

onDump

Added in 1.1.0
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-alpha10
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(): 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

Added in 1.1.0
fun onGetLayoutInflater(): LayoutInflater

Return a LayoutInflater. See getLayoutInflater.

onGetWindowAnimations

Added in 1.1.0
fun onGetWindowAnimations(): Int

Return the window animations.

onHasView

Added in 1.7.0-alpha10
fun onHasView(): Boolean

Return true if the container holds any view.

onHasWindowAnimations

Added in 1.1.0
fun onHasWindowAnimations(): Boolean

Return true if there are window animations.

onRequestPermissionsFromFragment

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

Requests permissions from the given fragment. See requestPermissions

onShouldSaveFragmentState

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

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

onShouldShowRequestPermissionRationale

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

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

onStartActivityFromFragment

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

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

onStartActivityFromFragment

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

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

onStartIntentSenderFromFragment

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

onSupportInvalidateOptionsMenu

Added in 1.1.0
fun onSupportInvalidateOptionsMenu(): Unit

Invalidates the activity's options menu. See supportInvalidateOptionsMenu