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:
ActivityResultRegistryOwner
: Removes the need to overrideonStartIntentSenderFromFragment
oronRequestPermissionsFromFragment
.FragmentOnAttachListener
: Removes the need to manually callFragmentManager#addFragmentOnAttachListener
from your host in order to receiveFragmentOnAttachListener#onAttachFragment
callbacks for theFragmentController#getSupportFragmentManager()
.androidx.activity.OnBackPressedDispatcherOwner
: Removes the need to manually callFragmentManager#popBackStackImmediate()
when handling the system back button.androidx.lifecycle.ViewModelStoreOwner
: Removes the need for yourFragmentController
to callFragmentController#retainNestedNonConfig()
orFragmentController#restoreAllState(Parcelable, FragmentManagerNonConfig)
.
Summary
Public constructors | |
---|---|
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? |
onFindViewById(id: Int) |
abstract E? |
Return the object that's currently hosting the fragment. |
open LayoutInflater |
Return a |
open Int |
Return the window animations. |
open Boolean | |
open Boolean |
Return |
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 |
open Boolean |
onShouldShowRequestPermissionRationale(@NonNull permission: String) Checks whether to show permission rationale UI from a fragment. |
open Unit |
onStartActivityFromFragment(@NonNull fragment: Fragment, intent: Intent!, requestCode: Int) Starts a new |
open Unit |
onStartActivityFromFragment(@NonNull fragment: Fragment, intent: Intent!, requestCode: Int, @Nullable options: Bundle?) Starts a new |
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 |
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. |
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()
.
onHasView
open fun onHasView(): Boolean
onHasWindowAnimations
open fun onHasWindowAnimations(): Boolean
Return true
if there are window animations.
onRequestPermissionsFromFragment
open funonRequestPermissionsFromFragment(
@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)