FragmentActivity

public class FragmentActivity extends ComponentActivity implements ContextAware, LifecycleOwner, ViewModelStoreOwner, HasDefaultViewModelProviderFactory, LifecycleOwner, SavedStateRegistryOwner, LifecycleOwner, OnBackPressedDispatcherOwner, ActivityResultRegistryOwner, ActivityResultCaller, MenuHost, ActivityCompat.OnRequestPermissionsResultCallback

Object
   ↳ ComponentActivity
     ↳ FragmentActivity
Known direct subclasses
AppCompatActivity

Base class for activities that wish to use some of the newer platform features on older Android devices.

CarAppActivity

The class representing a car app activity.


Base class for activities that want to use the support-based Fragments.

Known limitations:

  • When using the <fragment> tag, this implementation can not use the parent view's ID as the new fragment's ID. You must explicitly specify an ID (or tag) in the <fragment>.

Summary

Public constructors

Default constructor for FragmentActivity.

FragmentActivity(@LayoutRes @NonNull int contentLayoutId)

Alternate constructor that can be used to provide a default layout that will be inflated as part of super.onCreate(savedInstanceState).

Public methods

@Override @NonNull void
dump(
    @NonNull String prefix,
    @Nullable FileDescriptor fd,
    @NonNull PrintWriter writer,
    @Nullable Array<@NonNull String> args
)

Print the Activity's state into the given stream.

@NonNull FragmentManager

Return the FragmentManager for interacting with fragments associated with this activity.

@NonNull LoaderManager

This method is deprecated.

Use LoaderManager.getInstance(this).

@MainThread @NonNull void

This method is deprecated.

The responsibility for listening for fragments being attached has been moved to FragmentManager.

@Override @NonNull void

Dispatch configuration change to all fragments.

@Override @NonNull boolean
onCreatePanelMenu(@NonNull int featureId, @NonNull Menu menu)

Dispatch to Fragment.onCreateOptionsMenu().

@Override @Nullable View
onCreateView(
    @Nullable View parent,
    @NonNull String name,
    @NonNull Context context,
    @NonNull AttributeSet attrs
)
@Override @Nullable View
onCreateView(
    @NonNull String name,
    @NonNull Context context,
    @NonNull AttributeSet attrs
)
@Override @NonNull void

Dispatch onLowMemory() to all fragments.

@Override @NonNull boolean
onMenuItemSelected(@NonNull int featureId, @NonNull MenuItem item)

Dispatch context and options menu to fragments.

@Override @CallSuper @NonNull void
onMultiWindowModeChanged(@NonNull boolean isInMultiWindowMode)

Note: If you override this method you must call super.onMultiWindowModeChanged to correctly dispatch the event to support fragments attached to this activity.

@Override @NonNull void
onPanelClosed(@NonNull int featureId, @NonNull Menu menu)

Call onOptionsMenuClosed() on fragments.

@Override @CallSuper @NonNull void
onPictureInPictureModeChanged(@NonNull boolean isInPictureInPictureMode)

Note: If you override this method you must call super.onPictureInPictureModeChanged to correctly dispatch the event to support fragments attached to this activity.

@Override @NonNull boolean
onPreparePanel(
    @NonNull int featureId,
    @Nullable View view,
    @NonNull Menu menu
)

Dispatch onPrepareOptionsMenu() to fragments.

@CallSuper @Override @NonNull void
onRequestPermissionsResult(
    @NonNull int requestCode,
    @NonNull Array<@NonNull String> permissions,
    @NonNull Array<@NonNull int> grantResults
)

This method is deprecated.

use registerForActivityResult passing in a RequestMultiplePermissions object for the ActivityResultContract and handling the result in the callback.

@Override @NonNull void

Hook in to note that fragment state is no longer saved.

@NonNull void

When makeSceneTransitionAnimation was used to start an Activity, callback will be called to handle shared elements on the launched Activity.

@NonNull void

When makeSceneTransitionAnimation was used to start an Activity, listener will be called to handle shared elements on the launching Activity.

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

Called by Fragment.startActivityForResult() to implement its behavior.

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

Called by Fragment.startActivityForResult() to implement its behavior.

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

This method is deprecated.

Fragments should use registerForActivityResult with the StartIntentSenderForResult contract.

@NonNull void

Reverses the Activity Scene entry Transition and triggers the calling Activity to reverse its exit Transition.

@NonNull void

This method is deprecated.

Call invalidateOptionsMenu directly.

@NonNull void

Support library version of postponeEnterTransition that works only on API 21 and later.

@NonNull void

Support library version of startPostponedEnterTransition that only works with API 21 and later.

final @Override @NonNull void

This method is deprecated.

there are no longer any restrictions on permissions requestCodes.

Extension functions

final @NonNull BiometricPrompt.AuthenticationResult
Class2BiometricAuthExtensionsKt.authenticateWithClass2Biometrics(
    @NonNull FragmentActivity receiver,
    @NonNull CharSequence title,
    @NonNull CharSequence negativeButtonText,
    @Nullable CharSequence subtitle,
    @Nullable CharSequence description,
    boolean confirmationRequired
)

Prompts the user to authenticate with a Class 2 biometric (e.g.

final @NonNull AuthPrompt
Class2BiometricAuthExtensionsKt.startClass2BiometricAuthentication(
    @NonNull FragmentActivity receiver,
    @NonNull CharSequence title,
    @NonNull CharSequence negativeButtonText,
    @Nullable CharSequence subtitle,
    @Nullable CharSequence description,
    boolean confirmationRequired,
    @Nullable Executor executor,
    @NonNull AuthPromptCallback callback
)

Prompts the user to authenticate with a Class 2 biometric (e.g.

final @NonNull BiometricPrompt.AuthenticationResult
Class2BiometricOrCredentialAuthExtensionsKt.authenticateWithClass2BiometricsOrCredentials(
    @NonNull FragmentActivity receiver,
    @NonNull CharSequence title,
    @Nullable CharSequence subtitle,
    @Nullable CharSequence description,
    boolean confirmationRequired
)

Prompts the user to authenticate with a Class 2 biometric (e.g.

final @NonNull AuthPrompt
Class2BiometricOrCredentialAuthExtensionsKt.startClass2BiometricOrCredentialAuthentication(
    @NonNull FragmentActivity receiver,
    @NonNull CharSequence title,
    @Nullable CharSequence subtitle,
    @Nullable CharSequence description,
    boolean confirmationRequired,
    @Nullable Executor executor,
    @NonNull AuthPromptCallback callback
)

Prompts the user to authenticate with a Class 2 biometric (e.g.

final @NonNull AuthPrompt
Class3BiometricAuthExtensionsKt.authenticateWithClass3Biometrics(
    @NonNull FragmentActivity receiver,
    @Nullable BiometricPrompt.CryptoObject crypto,
    @NonNull CharSequence title,
    @NonNull CharSequence negativeButtonText,
    @Nullable CharSequence subtitle,
    @Nullable CharSequence description,
    boolean confirmationRequired,
    @Nullable Executor executor,
    @NonNull AuthPromptCallback callback
)

Prompts the user to authenticate with a Class 3 biometric (e.g.

final @NonNull BiometricPrompt.AuthenticationResult
Class3BiometricAuthExtensionsKt.authenticateWithClass3Biometrics(
    @NonNull FragmentActivity receiver,
    @Nullable BiometricPrompt.CryptoObject crypto,
    @NonNull CharSequence title,
    @NonNull CharSequence negativeButtonText,
    @Nullable CharSequence subtitle,
    @Nullable CharSequence description,
    boolean confirmationRequired
)

Prompts the user to authenticate with a Class 3 biometric (e.g.

final @RequiresApi(value = "30") @NonNull BiometricPrompt.AuthenticationResult
Class3BiometricOrCredentialAuthExtensionsKt.authenticateWithClass3BiometricsOrCredentials(
    @NonNull FragmentActivity receiver,
    @Nullable BiometricPrompt.CryptoObject crypto,
    @NonNull CharSequence title,
    @Nullable CharSequence subtitle,
    @Nullable CharSequence description,
    boolean confirmationRequired