public class ComponentActivity implements ContextAware, LifecycleOwner, ViewModelStoreOwner, HasDefaultViewModelProviderFactory, LifecycleOwner, SavedStateRegistryOwner, LifecycleOwner, OnBackPressedDispatcherOwner, ActivityResultRegistryOwner, ActivityResultCaller, MenuHost

Known direct subclasses

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

Known indirect subclasses

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


The class representing a car app activity.

Base class for activities that enables composition of higher level components.

Rather than all functionality being built directly into this class, only the minimal set of lower level building blocks are included. Higher level components can then be used as needed without enforcing a deep Activity class hierarchy or strong coupling between components.


Public constructors

Default constructor for ComponentActivity.

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

Adds the given MenuProvider to this MenuHost.

@Override void
    @NonNull MenuProvider provider,
    @NonNull LifecycleOwner owner

Adds the given MenuProvider to this MenuHost.

@Override void
    @NonNull MenuProvider provider,
    @NonNull LifecycleOwner owner,
    @NonNull Lifecycle.State state

Adds the given MenuProvider to this MenuHost once the given LifecycleOwner reaches the given Lifecycle.State.

final @Override void

Add a new for receiving a callback for when this class is associated with a .

final @NonNull @Override ActivityResultRegistry

Get the ActivityResultRegistry associated with this activity.

@NonNull @Override ViewModelProvider.Factory

Returns the default that should be used when no custom Factory} is provided to the constructors.

@Nullable Object

This method is deprecated.

Use a androidx.lifecycle.ViewModel to store non config state.

@NonNull @Override Lifecycle

Overriding this method is no longer supported and this method will be made final in a future version of ComponentActivity.

final @NonNull @Override OnBackPressedDispatcher

Retrieve the OnBackPressedDispatcher that will be triggered when onBackPressed is called.

final @NonNull @Override SavedStateRegistry

Returns owned SavedStateRegistry

@NonNull @Override ViewModelStore

Returns the ViewModelStore associated with this activity

@Override void

Invalidates the android.view.Menu to ensure that what is displayed matches the current internal state of the menu.

@Override @MainThread void

Called when the activity has detected the user's press of the back key.

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