FragmentHostCallback
public abstract class FragmentHostCallback<H extends Object> extends FragmentContainer
| java.lang.Object | ||
| ↳ | 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:
-
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 extends Object> |
the type of object that's currently hosting the fragments. An instance of this class must be returned by |
Summary
Public constructors |
|---|
Public methods |
|
|---|---|
void |
onDump(Print internal state into the given stream. |
View |
onFindViewById(int id)Return the view with the given resource ID. |
abstract @NonNull H |
Return the object that's currently hosting the fragment. |
@NonNull LayoutInflater |
Return a |
int |
Return the window animations. |
boolean |
Return |
boolean |
Return |
void |
This method is deprecated. Have your FragmentHostCallback implement {@link ActivityResultRegistryOwner} to allow Fragments to use {@link Fragment#registerForActivityResult(ActivityResultContract, ActivityResultCallback)} with {@link RequestMultiplePermissions}. |
boolean |
onShouldSaveFragmentState(@NonNull Fragment fragment)Return |
boolean |
onShouldShowRequestPermissionRationale(@NonNull String permission)Checks whether to show permission rationale UI from a fragment. |
void |
onStartActivityFromFragment(Starts a new |
void |
onStartActivityFromFragment(Starts a new |
void |
This method is deprecated. Have your FragmentHostCallback implement {@link ActivityResultRegistryOwner} to allow Fragments to use {@link Fragment#registerForActivityResult(ActivityResultContract, ActivityResultCallback)} with {@link StartIntentSenderForResult}. |
void |
Invalidates the activity's options menu. |
Inherited methods |
||
|---|---|---|
|
Public constructors
Public methods
onDump
public void onDump(
@NonNull String prefix,
FileDescriptor fd,
@NonNull PrintWriter writer,
String[] args
)
Print internal state into the given stream.
| Parameters | |
|---|---|
@NonNull String prefix |
Desired prefix to prepend at each line of output. |
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. |
String[] args |
additional arguments to the dump request. |
onFindViewById
public View onFindViewById(int id)
Return the view with the given resource ID. May return null if the view is not a child of this container.
onGetHost
public abstract @NonNull H 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.
onGetLayoutInflater
public @NonNull LayoutInflater onGetLayoutInflater()
Return a LayoutInflater. See Activity.getLayoutInflater.
onGetWindowAnimations
public int onGetWindowAnimations()
Return the window animations.
onHasWindowAnimations
public boolean onHasWindowAnimations()
Return true if there are window animations.
public voidonRequestPermissionsFromFragment(
@NonNull Fragment fragment,
@NonNull String[] permissions,
int requestCode
)
Requests permissions from the given fragment. See FragmentActivity.requestPermissions
onShouldSaveFragmentState
public boolean onShouldSaveFragmentState(@NonNull Fragment fragment)
Return true if the fragment's state needs to be saved.
onShouldShowRequestPermissionRationale
public boolean onShouldShowRequestPermissionRationale(@NonNull String permission)
Checks whether to show permission rationale UI from a fragment. See FragmentActivity.shouldShowRequestPermissionRationale
onStartActivityFromFragment
public void onStartActivityFromFragment(
@NonNull Fragment fragment,
@NonNull Intent intent,
int requestCode
)
Starts a new Activity from the given fragment. See FragmentActivity.startActivityForResult.
onStartActivityFromFragment
public void onStartActivityFromFragment(
@NonNull Fragment fragment,
@NonNull Intent intent,
int requestCode,
Bundle options
)
Starts a new Activity from the given fragment. See FragmentActivity.startActivityForResult.
public voidonStartIntentSenderFromFragment(
@NonNull Fragment fragment,
@NonNull IntentSender intent,
int requestCode,
Intent fillInIntent,
int flagsMask,
int flagsValues,
int extraFlags,
Bundle options
)
Starts a new IntentSender from the given fragment. See Activity.startIntentSender.
onSupportInvalidateOptionsMenu
public void onSupportInvalidateOptionsMenu()
Invalidates the activity's options menu. See FragmentActivity.supportInvalidateOptionsMenu