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 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 void
dump(
    @NonNull String prefix,
    @Nullable FileDescriptor fd,
    @NonNull PrintWriter writer,
    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 void

This method is deprecated.

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

@Override void

Dispatch configuration change to all fragments.

@Override boolean
onCreatePanelMenu(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 void

Dispatch onLowMemory() to all fragments.

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

Dispatch context and options menu to fragments.

@Override @CallSuper void
onMultiWindowModeChanged(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 void
onPanelClosed(int featureId, @NonNull Menu menu)

Call onOptionsMenuClosed() on fragments.

@Override @CallSuper void
onPictureInPictureModeChanged(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 boolean
onPreparePanel(int featureId, @Nullable View view, @NonNull Menu menu)

Dispatch onPrepareOptionsMenu() to fragments.

@CallSuper @Override void
onRequestPermissionsResult(
    int requestCode,
    String[] permissions,
    int[] grantResults
)

This method is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your activity.

@Override void

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

void

When