Google is committed to advancing racial equity for Black communities. See how.

FragmentActivity

open class FragmentActivity : ComponentActivity, ActivityCompat.OnRequestPermissionsResultCallback, RequestPermissionsRequestCodeValidator
androidx.activity.ComponentActivity
   ↳ androidx.fragment.app.FragmentActivity

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.

<init>(@LayoutRes contentLayoutId: Int)

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

Public methods
open Unit
dump(@NonNull prefix: String, @Nullable fd: FileDescriptor?, @NonNull writer: PrintWriter, @Nullable args: Array<String!>?)

Print the Activity's state into the given stream.

open FragmentManager

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

open LoaderManager

open Unit
onAttachFragment(@NonNull fragment: Fragment)

Called when a fragment is attached to the activity.

open Unit

Dispatch configuration change to all fragments.

open Boolean
onCreatePanelMenu(featureId: Int, @NonNull menu: Menu)

Dispatch to Fragment.

open View?
onCreateView(@Nullable parent: View?, @NonNull name: String, @NonNull context: Context, @NonNull attrs: AttributeSet)

open View?
onCreateView(@NonNull name: String, @NonNull context: Context, @NonNull attrs: AttributeSet)

open Unit

Dispatch onLowMemory() to all fragments.

open Boolean
onMenuItemSelected(featureId: Int, @NonNull item: MenuItem)

Dispatch context and options menu to fragments.

open Unit
onMultiWindowModeChanged(isInMultiWindowMode: Boolean)

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

open Unit
onPanelClosed(featureId: Int, @NonNull menu: Menu)

Call onOptionsMenuClosed() on fragments.

open Unit
onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean)

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

open Boolean
onPreparePanel(featureId: Int, @Nullable view: View?, @NonNull menu: Menu)

Dispatch onPrepareOptionsMenu() to fragments.

open Unit
onRequestPermissionsResult(requestCode: Int, @NonNull permissions: Array<String!>, @NonNull grantResults: IntArray)

open Unit

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

open Unit

When android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, * android.view.View, String) was used to start an Activity, callback will be called to handle shared elements on the launched Activity.

open Unit

When android.app.ActivityOptions#makeSceneTransitionAnimation(Activity, * android.view.View, String) was used to start an Activity, listener will be called to handle shared elements on the launching Activity.

open Unit
startActivityFromFragment(@NonNull fragment: Fragment, intent: Intent!, requestCode: Int)

Called by Fragment.

open Unit
startActivityFromFragment(@NonNull fragment: Fragment, intent: Intent!, requestCode: Int, @Nullable options: Bundle?)

Called by Fragment.

open Unit
startIntentSenderFromFragment(@NonNull fragment: Fragment, intent: IntentSender!, requestCode: Int, @Nullable fillInIntent: Intent?, flagsMask: Int, flagsValues: Int, extraFlags: Int, @Nullable options: Bundle?)

Called by Fragment.

open Unit

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

open Unit

Support library version of Activity#invalidateOptionsMenu.

open Unit

Support library version of android.app.Activity#postponeEnterTransition() that works only on API 21 and later.

open Unit

Support library version of android.app.Activity#startPostponedEnterTransition() that only works with API 21 and later.

Unit

Protected methods
open Unit
onActivityResult(requestCode: Int, resultCode: Int, @Nullable data: Intent?)

open Unit
onCreate(@Nullable savedInstanceState: Bundle?)

Perform initialization of all fragments.

open Unit

Destroy all fragments.

open Unit
onNewIntent(intent: Intent!)

Handle onNewIntent() to inform the fragment manager that the state is not saved.

open Unit

Dispatch onPause() to fragments.

open Unit

Dispatch onResume() to fragments.

open Unit

Dispatch onResume() to fragments.

open Unit

This is the fragment-orientated version of onResume() that you can override to perform operations in the Activity at the same point where its fragments are resumed.

open Unit

Dispatch onStart() to all fragments.

open Unit

Dispatch onStop() to all fragments.

Inherited functions

Public constructors

<init>

FragmentActivity()

Default constructor for FragmentActivity. All Activities must have a default constructor for API 27 and lower devices or when using the default android.app.AppComponentFactory.

<init>

FragmentActivity(@LayoutRes contentLayoutId: Int)

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

This should generally be called from your constructor that takes no parameters, as is required for API 27 and lower or when using the default android.app.AppComponentFactory.

Public methods

dump

open fun dump(
    @NonNull prefix: String,
    @Nullable fd: FileDescriptor?,
    @NonNull writer: PrintWriter,
    @Nullable args: Array<String!>?
): Unit

Print the Activity's state into the given stream. This gets invoked if you run "adb shell dumpsys activity ".

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.

getSupportFragmentManager

@NonNull open fun getSupportFragmentManager(): FragmentManager

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

getSupportLoaderManager

@NonNull open fun getSupportLoaderManager(): LoaderManager

Deprecated: Use LoaderManager.getInstance(this).

onAttachFragment

@MainThread open fun onAttachFragment(@NonNull fragment: Fragment): Unit

Deprecated: The responsibility for listening for fragments being attached has been moved to FragmentManager. You can add a listener to this Activity's FragmentManager by calling FragmentManager#addFragmentOnAttachListener(FragmentOnAttachListener) in your constructor to get callbacks when a fragment is attached directly to the activity's FragmentManager.

Called when a fragment is attached to the activity.

This is called after the attached fragment's onAttach and before the attached fragment's onCreate if the fragment has not yet had a previous call to onCreate.

onConfigurationChanged

open fun onConfigurationChanged(@NonNull newConfig: Configuration): Unit

Dispatch configuration change to all fragments.

onCreatePanelMenu

open fun onCreatePanelMenu(
    featureId: Int,
    @NonNull menu: Menu
): Boolean

Dispatch to Fragment.onCreateOptionsMenu().

onCreateView

@Nullable open fun onCreateView(
    @Nullable parent: View?,
    @NonNull name: String,
    @NonNull context: Context,
    @NonNull attrs: AttributeSet
): View?

onCreateView

@Nullable open fun onCreateView(
    @NonNull name: String,
    @NonNull context: Context,
    @NonNull attrs: AttributeSet
): View?

onLowMemory

open fun onLowMemory(): Unit

Dispatch onLowMemory() to all fragments.

onMenuItemSelected

open fun onMenuItemSelected(
    featureId: Int,
    @NonNull item: MenuItem
): Boolean

Dispatch context and options menu to fragments.

onMultiWindowModeChanged

@CallSuper open fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean): Unit

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

Parameters
isInMultiWindowMode Boolean: True if the activity is in multi-window mode.

onPanelClosed

open fun onPanelClosed(
    featureId: Int,
    @NonNull menu: Menu
): Unit

Call onOptionsMenuClosed() on fragments.