ComponentActivity

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

Known direct subclasses
FragmentActivity

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

Known indirect 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 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.

Summary

Public constructors

Default constructor for ComponentActivity.

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

Adds the given MenuProvider to this MenuHost.

@Override @NonNull void
addMenuProvider(
    @NonNull MenuProvider provider,
    @NonNull LifecycleOwner owner
)

Adds the given MenuProvider to this MenuHost.

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

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

@Override @MainThread @NonNull void

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

@Override @NonNull boolean