FragmentHostCallback

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:

Parameters
<E>

the type of object that's currently hosting the fragments. An instance of this class must be returned by onGetHost.

Summary

Public constructors

FragmentHostCallback(
    @NonNull Context context,
    @NonNull Handler handler,
    int windowAnimations
)

Public methods

void
onDump(
    @NonNull String prefix,
    @Nullable FileDescriptor fd,
    @NonNull PrintWriter writer,
    @Nullable String[] args
)

Print internal state into the given stream.

@Nullable View

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.

int

Return the window animations.

boolean

Return true if the container holds any view.

boolean

Return true if there are window animations.

void
onRequestPermissionsFromFragment(
    @NonNull Fragment fragment,
    @NonNull String[] permissions,
    int requestCode
)

This method is deprecated.

Have your FragmentHostCallback implement ActivityResultRegistryOwner to allow Fragments to use registerForActivityResult with RequestMultiplePermissions.

boolean

Return true if the fragment's state needs to be saved.

boolean

Checks whether to show permission rationale UI from a fragment.

void
onStartActivityFromFragment(
    @NonNull Fragment fragment,
    @NonNull Intent intent,
    int requestCode
)

Starts a new Activity from the given fragment.

void
onStartActivityFromFragment(
    @NonNull Fragment fragment,
    @NonNull Intent intent,
    int requestCode,
    @Nullable Bundle options
)

Starts a new Activity from the given fragment.

void
onStartIntentSenderFromFragment(
    @NonNull Fragment fragment,
    @NonNull IntentSender intent,
    int requestCode,
    @Nullable Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    @Nullable Bundle options
)

This method is deprecated.

Have your FragmentHostCallback implement ActivityResultRegistryOwner to allow Fragments to use registerForActivityResult with StartIntentSenderForResult.

void

Invalidates the activity's options menu.

Inherited methods

From androidx.fragment.app.FragmentContainer
@NonNull Fragment
instantiate(
    @NonNull Context context,
    @NonNull String className,
    @Nullable Bundle arguments
)

This method is deprecated.

Use setFragmentFactory to control how Fragments are instantiated.

Public constructors

FragmentHostCallback

Added in 1.1.0
public FragmentHostCallback(
    @NonNull Context context,
    @NonNull Handler handler,
    int windowAnimations
)

Public methods

onDump

Added in 1.1.0
public void onDump(
    @NonNull String prefix,
    @Nullable FileDescriptor fd,
    @NonNull PrintWriter writer,
    @Nullable 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 String[] args

additional arguments to the dump request.

onFindViewById

Added in 1.7.0-alpha10
public @Nullable 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

Added in 1.1.0
public abstract @NullableonGetHost()

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 getActivity.

onGetLayoutInflater

Added in 1.1.0
public @NonNull LayoutInflater onGetLayoutInflater()

Return a LayoutInflater. See getLayoutInflater.

onGetWindowAnimations

Added in 1.1.0
public int onGetWindowAnimations()

Return the window animations.

onHasView

Added in 1.7.0-alpha10
public boolean onHasView()

Return true if the container holds any view.

onHasWindowAnimations

Added in 1.1.0
public boolean onHasWindowAnimations()

Return true if there are window animations.

onRequestPermissionsFromFragment

Added in 1.1.0
Deprecated in 1.3.0
public void onRequestPermissionsFromFragment(
    @NonNull Fragment fragment,
    @NonNull String[] permissions,
    int requestCode
)

Requests permissions from the given fragment. See requestPermissions

onShouldSaveFragmentState

Added in 1.1.0
public boolean onShouldSaveFragmentState(@NonNull Fragment fragment)

Return true if the fragment's state needs to be saved.

onShouldShowRequestPermissionRationale

Added in 1.1.0
public boolean onShouldShowRequestPermissionRationale(@NonNull String permission)

Checks whether to show permission rationale UI from a fragment. See shouldShowRequestPermissionRationale

onStartActivityFromFragment

Added in 1.1.0
public void onStartActivityFromFragment(
    @NonNull Fragment fragment,
    @NonNull Intent intent,
    int requestCode
)

Starts a new Activity from the given fragment. See startActivityForResult.

onStartActivityFromFragment

Added in 1.1.0
public void onStartActivityFromFragment(
    @NonNull Fragment fragment,
    @NonNull Intent intent,
    int requestCode,
    @Nullable Bundle options
)

Starts a new Activity from the given fragment. See startActivityForResult.

onStartIntentSenderFromFragment

Added in 1.1.0
Deprecated in 1.3.0
public void onStartIntentSenderFromFragment(
    @NonNull Fragment fragment,
    @NonNull IntentSender intent,
    int requestCode,
    @Nullable Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    @Nullable Bundle options
)

Starts a new IntentSender from the given fragment. See startIntentSender.

onSupportInvalidateOptionsMenu

Added in 1.1.0
public void onSupportInvalidateOptionsMenu()

Invalidates the activity's options menu. See supportInvalidateOptionsMenu