{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
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:
onStartIntentSenderFromFragment
or onRequestPermissionsFromFragment
.FragmentOnAttachListener
: Removes the need to manually call FragmentManager#addFragmentOnAttachListener
from your host in order to receive FragmentOnAttachListener#onAttachFragment
callbacks for the FragmentController#getSupportFragmentManager()
.FragmentManager#popBackStackImmediate()
when handling the system back button.FragmentController
to call FragmentController#retainNestedNonConfig()
or FragmentController#restoreAllState(Parcelable, FragmentManagerNonConfig)
.Parameters | |
---|---|
<E> |
the type of object that's currently hosting the fragments. An instance of this class must be returned by |
Public constructors |
|
---|---|
FragmentHostCallback( |
Public functions |
|
---|---|
Unit |
onDump( Print internal state into the given stream. |
View? |
onFindViewById(id: Int) 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 |
Boolean |
Return |
Unit |
This function is deprecated. Have your FragmentHostCallback implement ActivityResultRegistryOwner to allow Fragments to use |
Boolean |
onShouldSaveFragmentState(fragment: Fragment) Return |
Boolean |
onShouldShowRequestPermissionRationale(permission: String) Checks whether to show permission rationale UI from a fragment. |
Unit |
onStartActivityFromFragment( Starts a new Activity from the given fragment. |
Unit |
onStartActivityFromFragment( Starts a new Activity from the given fragment. |
Unit |
This function is deprecated. Have your FragmentHostCallback implement ActivityResultRegistryOwner to allow Fragments to use |
Unit |
Invalidates the activity's options menu. |
Inherited functions |
||
---|---|---|
|
FragmentHostCallback(
context: Context,
handler: Handler,
windowAnimations: Int
)
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. |
fun onFindViewById(id: Int): View?
Return the view with the given resource ID. May return {@code null}
if the view is not a child of this container.
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()
.
fun onGetLayoutInflater(): LayoutInflater
Return a LayoutInflater. See Activity#getLayoutInflater().
fun onHasWindowAnimations(): Boolean
Return {@code true}
if there are window animations.
funonRequestPermissionsFromFragment(
fragment: Fragment,
permissions: Array<String>,
requestCode: Int
): Unit
Requests permissions from the given fragment. See FragmentActivity#requestPermissions(String[], int)
fun onShouldSaveFragmentState(fragment: Fragment): Boolean
Return {@code true}
if the fragment's state needs to be saved.
fun onShouldShowRequestPermissionRationale(permission: String): Boolean
Checks whether to show permission rationale UI from a fragment. See FragmentActivity#shouldShowRequestPermissionRationale(String)
fun onStartActivityFromFragment(
fragment: Fragment,
intent: Intent,
requestCode: Int
): Unit
Starts a new Activity from the given fragment. See FragmentActivity#startActivityForResult(Intent, int).
fun onStartActivityFromFragment(
fragment: Fragment,
intent: Intent,
requestCode: Int,
options: Bundle?
): Unit
Starts a new Activity from the given fragment. See FragmentActivity#startActivityForResult(Intent, int, Bundle).
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(IntentSender, Intent, int, int, int, Bundle).
fun onSupportInvalidateOptionsMenu(): Unit
Invalidates the activity's options menu. See FragmentActivity#supportInvalidateOptionsMenu()