{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
public abstract class FragmentHostCallback<E> extends 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 methods |
|
---|---|
@NonNull void |
onDump( Print internal state into the given stream. |
@Nullable View |
onFindViewById(@NonNull int id) Return the view with the given resource ID. |
abstract @Nullable E |
Return the object that's currently hosting the fragment. |
@NonNull LayoutInflater |
Return a LayoutInflater. |
@NonNull int |
Return the window animations. |
@NonNull boolean |
Return |
@NonNull boolean |
Return |
@NonNull void |
This method is deprecated. Have your FragmentHostCallback implement ActivityResultRegistryOwner to allow Fragments to use |
@NonNull boolean |
onShouldSaveFragmentState(@NonNull Fragment fragment) Return |
@NonNull boolean |
onShouldShowRequestPermissionRationale(@NonNull String permission) Checks whether to show permission rationale UI from a fragment. |
@NonNull void |
onStartActivityFromFragment( Starts a new Activity from the given fragment. |
@NonNull void |
onStartActivityFromFragment( Starts a new Activity from the given fragment. |
@NonNull void |
This method is deprecated. Have your FragmentHostCallback implement ActivityResultRegistryOwner to allow Fragments to use |
@NonNull void |
Invalidates the activity's options menu. |
Inherited methods |
||
---|---|---|
|
@NonNull
public FragmentHostCallback(
@NonNull Context context,
@NonNull Handler handler,
@NonNull int windowAnimations
)
@NonNull
public void onDump(
@NonNull String prefix,
@Nullable FileDescriptor fd,
@NonNull PrintWriter writer,
@Nullable Array<@NonNull String> args
)
Print internal state into the given stream.
Parameters | |
---|---|
@NonNull String prefix |
Desired prefix to prepend at each line of output. |
@Nullable FileDescriptor fd |
The raw file descriptor that the dump is being sent to. |
@NonNull PrintWriter writer |
The PrintWriter to which you should dump your state. This will be closed for you after you return. |
@Nullable Array<@NonNull String> args |
additional arguments to the dump request. |
@Nullable
@NonNull
public View onFindViewById(@NonNull int id)
Return the view with the given resource ID. May return {@code null}
if the view is not a child of this container.
@Nullable
@NonNull
public abstract E onGetHost()
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()
.
@NonNull
public LayoutInflater onGetLayoutInflater()
Return a LayoutInflater. See Activity#getLayoutInflater().
@NonNull
public boolean onHasWindowAnimations()
Return {@code true}
if there are window animations.
@NonNull
public voidonRequestPermissionsFromFragment(
@NonNull Fragment fragment,
@NonNull Array<@NonNull String> permissions,
@NonNull int requestCode
)
Requests permissions from the given fragment. See FragmentActivity#requestPermissions(String[], int)
@NonNull
public boolean onShouldSaveFragmentState(@NonNull Fragment fragment)
Return {@code true}
if the fragment's state needs to be saved.
@NonNull
public boolean onShouldShowRequestPermissionRationale(@NonNull String permission)
Checks whether to show permission rationale UI from a fragment. See FragmentActivity#shouldShowRequestPermissionRationale(String)
@NonNull
public void onStartActivityFromFragment(
@NonNull Fragment fragment,
@NonNull Intent intent,
@NonNull int requestCode
)
Starts a new Activity from the given fragment. See FragmentActivity#startActivityForResult(Intent, int).
@NonNull
public void onStartActivityFromFragment(
@NonNull Fragment fragment,
@NonNull Intent intent,
@NonNull int requestCode,
@Nullable Bundle options
)
Starts a new Activity from the given fragment. See FragmentActivity#startActivityForResult(Intent, int, Bundle).
@NonNull
public voidonStartIntentSenderFromFragment(
@NonNull Fragment fragment,
@NonNull IntentSender intent,
@NonNull int requestCode,
@Nullable Intent fillInIntent,
@NonNull int flagsMask,
@NonNull int flagsValues,
@NonNull int extraFlags,
@Nullable Bundle options
)
Starts a new IntentSender from the given fragment. See Activity#startIntentSender(IntentSender, Intent, int, int, int, Bundle).
@NonNull
public void onSupportInvalidateOptionsMenu()
Invalidates the activity's options menu. See FragmentActivity#supportInvalidateOptionsMenu()