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:
-
androidx.activity.result.ActivityResultRegistryOwner: Removes the need to override .onStartIntentSenderFromFragment or .onRequestPermissionsFromFragment. -
FragmentOnAttachListener: Removes the need to manually callFragmentManager.addFragmentOnAttachListenerfrom your host in order to receiveFragmentOnAttachListener.onAttachFragmentcallbacks for theFragmentController.getSupportFragmentManager. -
androidx.activity.OnBackPressedDispatcherOwner: Removes the need to manually callFragmentManager.popBackStackImmediatewhen handling the system back button. -
androidx.lifecycle.ViewModelStoreOwner: Removes the need for yourFragmentControllerto callFragmentController.retainNestedNonConfigorFragmentController.restoreAllState.
| Parameters | |
|---|---|
<H : Any?> |
the type of object that's currently hosting the fragments. An instance of this class must be returned by |
Summary
Public constructors |
|---|
<H : Any?> FragmentHostCallback( |
Public functions |
|
|---|---|
open Unit |
onDump(Print internal state into the given stream. |
open View? |
onFindViewById(id: Int)Return the view with the given resource ID. |
abstract H |
Return the object that's currently hosting the fragment. |
open LayoutInflater |
Return a |
open Int |
Return the window animations. |
open Boolean |
Return |
open Boolean |
Return |
open Unit |
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 |
onShouldSaveFragmentState(fragment: Fragment)Return |
open Boolean |
onShouldShowRequestPermissionRationale(permission: String)Checks whether to show permission rationale UI from a fragment. |
open Unit |
onStartActivityFromFragment(Starts a new |
open Unit |
onStartActivityFromFragment(Starts a new |
open Unit |
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 |
||
|---|---|---|
|
Public constructors
FragmentHostCallback
<H : Any?> FragmentHostCallback(
context: Context,
handler: Handler,
windowAnimations: Int
)
Public functions
onDump
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
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
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
open fun onGetLayoutInflater(): LayoutInflater
Return a LayoutInflater. See Activity.getLayoutInflater.
onGetWindowAnimations
open fun onGetWindowAnimations(): Int
Return the window animations.
onHasWindowAnimations
open fun onHasWindowAnimations(): Boolean
Return true if there are window animations.
open funonRequestPermissionsFromFragment(
fragment: Fragment,
permissions: Array<String>,
requestCode: Int
): Unit
Requests permissions from the given fragment. See FragmentActivity.requestPermissions
onShouldSaveFragmentState
open fun onShouldSaveFragmentState(fragment: Fragment): Boolean
Return true if the fragment's state needs to be saved.
onShouldShowRequestPermissionRationale
open fun onShouldShowRequestPermissionRationale(permission: String): Boolean
Checks whether to show permission rationale UI from a fragment. See FragmentActivity.shouldShowRequestPermissionRationale
onStartActivityFromFragment
open fun onStartActivityFromFragment(
fragment: Fragment,
intent: Intent,
requestCode: Int
): Unit
Starts a new Activity from the given fragment. See FragmentActivity.startActivityForResult.
onStartActivityFromFragment
open fun onStartActivityFromFragment(
fragment: Fragment,
intent: Intent,
requestCode: Int,
options: Bundle?
): Unit
Starts a new Activity from the given fragment. See FragmentActivity.startActivityForResult.
open funonStartIntentSenderFromFragment(
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
open fun onSupportInvalidateOptionsMenu(): Unit
Invalidates the activity's options menu. See FragmentActivity.supportInvalidateOptionsMenu