ComponentActivity


public class ComponentActivity extends Activity implements LifecycleOwner, ContextAware, ViewModelStoreOwner, HasDefaultViewModelProviderFactory, SavedStateRegistryOwner, OnBackPressedDispatcherOwner, NavigationEventDispatcherOwner, ActivityResultRegistryOwner, ActivityResultCaller, OnConfigurationChangedProvider, OnTrimMemoryProvider, OnNewIntentProvider, OnMultiWindowModeChangedProvider, PictureInPictureProvider, MenuHost, FullyDrawnReporterOwner

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.

BaseCarAppActivity

Core logic for CarAppLibrary Activity interaction with a host.

CarAppActivity

The class representing a car app activity in the main display.

LauncherActivity

This class handles providing the right launcher activity when running native applications and Car App Library applications.


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

@ContentView
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

void
void

Adds the given MenuProvider to this MenuHost.

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

Adds the given MenuProvider to this MenuHost.

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 void

Add a new listener that will get a callback associated with ComponentCallbacks.onConfigurationChanged with the new Configuration.

final void

{@inheritDoc}

final void

Add a new listener that will get a callback associated with Activity.onMultiWindowModeChanged with the new MultiWindowModeChangedInfo.

final void

Add a new listener that will get a callback associated with Activity.onNewIntent with the new Intent.

final void

Add a new listener that will get a callback associated with Activity.onPictureInPictureModeChanged with the new PictureInPictureModeChangedInfo.

final void

Add a new listener that will get a callback associated with Activity.onPictureInPictureUiStateChanged with the new PictureInPictureUiStateCompat.

final void

Add a new listener that will get a callback associated with ComponentCallbacks2.onTrimMemory with the int representing the level of trimming.

final void

Add a new listener that will get a callback associated with Activity.onUserLeaveHint

final void

Available since API 24 in the framework Activity class, puts the activity in picture-in-picture mode if possible in the current system state.

final @NonNull ActivityResultRegistry

Get the ActivityResultRegistry associated with this activity.

@NonNull CreationExtras

{@inheritDoc}

final @NonNull ViewModelProvider.Factory
final @NonNull FullyDrawnReporter

Retrieve the FullyDrawnReporter that should handle the independent parts of the UI that separately report that they are fully drawn.

Object

This method is deprecated. Use a {@link androidx.lifecycle.ViewModel} to store non config state.

@NonNull Lifecycle

{@inheritDoc}

@NonNull NavigationEventDispatcher

Lazily provides a NavigationEventDispatcher for back navigation handling, including support for predictive back gestures introduced in Android 13 (API 33+).

final @NonNull OnBackPressedDispatcher

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

final @NonNull SavedStateRegistry
@NonNull ViewModelStore

Returns the ViewModelStore associated with this activity

void

Sets the view tree owners before setting the content view so that the inflation process and attach listeners will see them already present.

void

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

void

This method is deprecated. This method has been deprecated in favor of using the {@link OnBackPressedDispatcher} via {@link #getOnBackPressedDispatcher()}.

void

{@inheritDoc}

boolean
onCreatePanelMenu(int featureId, @NonNull Menu menu)
boolean
onMenuItemSelected(int featureId, @NonNull MenuItem item)
void
@CallSuper
onMultiWindowModeChanged(boolean isInMultiWindowMode)

This method is deprecated. Deprecated in android.app.Activity

void
@RequiresApi(api = 26)
@CallSuper
onMultiWindowModeChanged(
    boolean isInMultiWindowMode,
    @NonNull Configuration newConfig
)

{@inheritDoc}

void
onPanelClosed(int featureId, @NonNull Menu menu)
void
@CallSuper
onPictureInPictureModeChanged(boolean isInPictureInPictureMode)

This method is deprecated. Deprecated in android.app.Activity

void
@RequiresApi(api = 26)
@CallSuper
onPictureInPictureModeChanged(
    boolean isInPictureInPictureMode,
    @NonNull Configuration newConfig
)

{@inheritDoc}

void

{@inheritDoc}

boolean
onPreparePanel(int featureId, View view, @NonNull Menu menu)
void
@CallSuper
onRequestPermissionsResult(
    int requestCode,
    @NonNull String[] permissions,
    @NonNull 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 {@link ActivityResultContract} and the prebuilt contracts for common intents available in {@link androidx.activity.result.contract.ActivityResultContracts}, provides hooks for testing, and allow receiving results in separate, testable classes independent from your activity.

Object

This method is deprecated. Use a {@link androidx.lifecycle.ViewModel} to store non config state.

final Object

Retain all appropriate non-config state.

void

{@inheritDoc}

Context

Get the Context if it is currently available.

final @NonNull ActivityResultLauncher<@NonNull I>
<I extends Object, O extends Object> registerForActivityResult(
    @NonNull ActivityResultContract<@NonNull I, @NonNull O> contract,
    @NonNull ActivityResultCallback<@NonNull O> callback
)

Register a request to start an activity for result, designated by the given contract.

final @NonNull ActivityResultLauncher<@NonNull I>
<I extends Object, O extends Object> registerForActivityResult(
    @NonNull ActivityResultContract<@NonNull I, @NonNull O> contract,
    @NonNull ActivityResultRegistry registry,
    @NonNull ActivityResultCallback<@NonNull O> callback
)

Register a request to start an activity for result, designated by the given contract.

void

Removes the given MenuProvider from this MenuHost.

final void

Remove a previously added listener.

final void

Remove a OnContextAvailableListener previously added via addOnContextAvailableListener.

final void

Remove a previously added listener.

final void

Remove a previously added listener.

final void

Remove a previously added listener.

final void

Remove a previously added listener.

final void

Remove a previously added listener.

final void

Remove a previously added listener.

void
void
setContentView(@LayoutRes int layoutResID)
void
void
final void

Available since API 26 in the framework Activity class, updates the properties of the picture-in-picture activity, or sets it to be used later when enterPictureInPictureMode is called

void
startActivityForResult(@NonNull Intent intent, int requestCode)

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

void
startActivityForResult(
    @NonNull Intent intent,
    int requestCode,
    Bundle options
)

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

void
startIntentSenderForResult(
    @NonNull IntentSender intent,
    int requestCode,
    Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags
)

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

void
startIntentSenderForResult(
    @NonNull IntentSender intent,
    int requestCode,
    Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    Bundle options
)

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

Protected methods

void
@CallSuper
onActivityResult(int requestCode, int resultCode, Intent data)

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

void
onCreate(Bundle savedInstanceState)

{@inheritDoc}

void

{@inheritDoc}

void
void

{@inheritDoc}

Extension functions

final @NonNull Lazy<@NonNull VM>
@MainThread
<VM extends ViewModel> ActivityViewModelLazyKt.viewModels(
    @NonNull ComponentActivity receiver,
    Function0<@NonNull CreationExtras> extrasProducer,
    Function0<@NonNull ViewModelProvider.Factory> factoryProducer
)

Returns a Lazy delegate to access the ComponentActivity's ViewModel, if factoryProducer is specified then ViewModelProvider.Factory returned by it will be used to create ViewModel first time.

final void
EdgeToEdge.enableEdgeToEdge(
    @NonNull ComponentActivity receiver,
    @NonNull SystemBarStyle statusBarStyle,
    @NonNull SystemBarStyle navigationBarStyle
)

Enables the edge-to-edge display for this ComponentActivity.

Inherited methods

From android.app.Activity
void
void
void
@NonNull PendingIntent
createPendingResult(int requestCode, @NonNull Intent data, int flags)
final void
dismissDialog(int id)

This method is deprecated. Deprecated in Java

final void
void
dump(
    @NonNull String prefix,
    @Nullable FileDescriptor fd,
    @NonNull PrintWriter writer,
    @Nullable String[] args
)
void

This method is deprecated. Deprecated in Java

boolean
@NonNull T
<T extends View> findViewById(int id)
void
void
finishActivity(int requestCode)
void
finishActivityFromChild(@NonNull Activity child, int requestCode)

This method is deprecated. Deprecated in Java

void
void
void
void

This method is deprecated. Deprecated in Java

@Nullable ActionBar
final @NonNull Application
@Nullable ComponentCaller
@Nullable ComponentName
@Nullable String
int
@NonNull ComponentName
@NonNull Scene
@NonNull TransitionManager
@NonNull ComponentCaller
@Nullable View
@NonNull FragmentManager

This method is deprecated. Deprecated in Java

@NonNull ComponentCaller
@NonNull Intent
@Nullable Object
@Nullable String
int
@NonNull LayoutInflater
@NonNull LoaderManager

This method is deprecated. Deprecated in Java

@NonNull String
int
final @NonNull MediaController
@NonNull MenuInflater
@NonNull OnBackInvokedDispatcher
final @NonNull Activity

This method is deprecated. Deprecated in Java

@Nullable Intent
@NonNull SharedPreferences
getPreferences(int mode)
@Nullable Uri
int
final @NonNull SearchEvent
final @NonNull SplashScreen
int
final @NonNull CharSequence
final int
@NonNull VoiceInteractor
final int
@NonNull Window
@NonNull WindowManager
boolean
void
boolean
boolean
final boolean

This method is deprecated. Deprecated in Java

boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final @NonNull Cursor
managedQuery(
    @NonNull Uri uri,
    @NonNull String[] projection,
    @NonNull String selection,
    @NonNull String[] selectionArgs,
    @NonNull String sortOrder
)

This method is deprecated. Deprecated in Java

boolean
moveTaskToBack(boolean nonRoot)
boolean
boolean

This method is deprecated. Deprecated in Java

void
onActivityReenter(int resultCode, @NonNull Intent data)
void
onActivityResult(
    int requestCode,
    int resultCode,
    @Nullable Intent data,
    @NonNull ComponentCaller caller
)
void

This method is deprecated. Deprecated in Java

void
onChildTitleChanged(
    @NonNull Activity childActivity,
    @NonNull CharSequence title
)
boolean
void
void
onCreate(
    @Nullable Bundle savedInstanceState,
    @Nullable PersistableBundle persistentState
)
@Nullable CharSequence
@NonNull Dialog

This method is deprecated. Deprecated in Java

@Nullable Dialog
onCreateDialog(int id, @NonNull Bundle args)

This method is deprecated. Deprecated in Java

void
boolean
boolean

This method is deprecated. Deprecated in Java

void
void
boolean
void
onGetDirectActions(
    @NonNull CancellationSignal cancellationSignal,
    @NonNull Consumer<@NonNull List<@NonNull DirectAction>> callback
)
boolean
onKeyShortcut(int keyCode, @NonNull KeyEvent event)
void
void
boolean
boolean

This method is deprecated. Deprecated in Java

void
boolean
void
void
void
onPerformDirectAction(
    @NonNull String actionId,
    @NonNull Bundle arguments,
    @NonNull CancellationSignal cancellationSignal,
    @NonNull Consumer<@NonNull Bundle> resultListener
)
boolean
void
onPostCreate(@Nullable Bundle savedInstanceState)
void
onPostCreate(
    @Nullable Bundle savedInstanceState,
    @Nullable PersistableBundle persistentState
)
void
void
onPrepareDialog(int id, @NonNull Dialog dialog)

This method is deprecated. Deprecated in Java

void
onPrepareDialog(int id, @NonNull Dialog dialog, @NonNull Bundle args)

This method is deprecated. Deprecated in Java

void
boolean
void
void
@NonNull Uri
void
onRequestPermissionsResult(
    int requestCode,
    @NonNull String[] permissions,
    @NonNull int[] grantResults,
    int deviceId
)
void
void
onRestoreInstanceState(@NonNull Bundle savedInstanceState)
void
onRestoreInstanceState(
    @Nullable Bundle savedInstanceState,
    @Nullable PersistableBundle persistentState
)
void
void
onSaveInstanceState(
    @NonNull Bundle outState,
    @NonNull PersistableBundle outPersistentState
)
void
void

This method is deprecated. Deprecated in Java

void
void
onTitleChanged(@NonNull CharSequence title, int color)
void
onTopResumedActivityChanged(boolean isTopResumedActivity)
boolean
boolean
void
void

This method is deprecated. Deprecated in Java

void
void
void
overrideActivityTransition(
    int overrideType,
    int enterAnim,
    int exitAnim
)
void
overrideActivityTransition(
    int overrideType,
    int enterAnim,
    int exitAnim,
    int backgroundColor
)
void
overridePendingTransition(int enterAnim, int exitAnim)

This method is deprecated. Deprecated in Java

void
overridePendingTransition(
    int enterAnim,
    int exitAnim,
    int backgroundColor
)

This method is deprecated. Deprecated in Java

void
void
void
void
void
boolean
final void
removeDialog(int id)

This method is deprecated. Deprecated in Java

@NonNull DragAndDropPermissions
void
requestFullscreenMode(
    int request,
    @Nullable OutcomeReceiver<@NonNull Void, @NonNull Throwable> approvalCallback
)
final void
final void
requestPermissions(@NonNull String[] permissions, int requestCode)
final void
requestPermissions(
    @NonNull String[] permissions,
    int requestCode,
    int deviceId
)
final void
boolean
requestVisibleBehind(boolean visible)

This method is deprecated. Deprecated in Java

final boolean
requestWindowFeature(int featureId)
final @NonNull T
<T extends View> requireViewById(int id)
final void
void
void
void
final void
void
void
final void
setFeatureDrawable(int featureId, @NonNull Drawable drawable)
final void
setFeatureDrawableAlpha(int featureId, int alpha)
final void
setFeatureDrawableResource(int featureId, int resId)
final void
setFeatureDrawableUri(int featureId, @NonNull Uri uri)
void
setFinishOnTouchOutside(boolean finish)
void
setImmersive(boolean i)
void
setInheritShowWhenLocked(boolean inheritShowWhenLocked)
void
setIntent(@NonNull Intent newIntent)
void
final void
void
final void
setProgress(int progress)

This method is deprecated. Deprecated in Java

final void
setProgressBarIndeterminate(boolean indeterminate)

This method is deprecated. Deprecated in Java

final void

This method is deprecated. Deprecated in Java

final void
setProgressBarVisibility(boolean visible)

This method is deprecated. Deprecated in Java

void
setRecentsScreenshotEnabled(boolean enabled)
void
setRequestedOrientation(int requestedOrientation)
final void
setResult(int resultCode)
final void
setResult(int resultCode, @NonNull Intent data)
final void
setSecondaryProgress(int secondaryProgress)

This method is deprecated. Deprecated in Java

void
setShouldDockBigOverlays(boolean shouldDockBigOverlays)
void
setShowWhenLocked(boolean showWhenLocked)
void
void
void
setTitleColor(int textColor)

This method is deprecated. Deprecated in Java

boolean
setTranslucent(boolean translucent)
void
setTurnScreenOn(boolean turnScreenOn)
void
setVisible(boolean visible)
final void
setVolumeControlStream(int streamType)
void
setVrModeEnabled(
    boolean enabled,
    @NonNull ComponentName requestedComponent
)
boolean
boolean
boolean
shouldShowRequestPermissionRationale(
    @NonNull String permission,
    int deviceId
)
boolean
boolean
final void
showDialog(int id)

This method is deprecated. Deprecated in Java

final boolean
showDialog(int id, @NonNull Bundle args)

This method is deprecated. Deprecated in Java

void
@Nullable ActionMode
@Nullable ActionMode
void
startActivityFromChild(
    @NonNull Activity child,
    @NonNull Intent intent,
    int requestCode
)

This method is deprecated. Deprecated in Java

void
startActivityFromChild(
    @NonNull Activity child,
    @NonNull Intent intent,
    int requestCode,
    @Nullable Bundle options
)

This method is deprecated. Deprecated in Java

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

This method is deprecated. Deprecated in Java

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

This method is deprecated. Deprecated in Java

boolean
startActivityIfNeeded(@NonNull Intent intent, int requestCode)
boolean
startActivityIfNeeded(
    @NonNull Intent intent,
    int requestCode,
    @Nullable Bundle options
)
void
startIntentSenderFromChild(
    @NonNull Activity child,
    @NonNull IntentSender intent,
    int requestCode,
    @NonNull Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags
)

This method is deprecated. Deprecated in Java

void
startIntentSenderFromChild(
    @NonNull Activity child,
    @NonNull IntentSender intent,
    int requestCode,
    @NonNull Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    @Nullable Bundle options
)

This method is deprecated. Deprecated in Java

void
void
void

This method is deprecated. Deprecated in Java

boolean
boolean
void
void
startSearch(
    @Nullable String initialQuery,
    boolean selectInitialQuery,
    @Nullable Bundle appSearchData,
    boolean globalSearch
)
void
void
void

This method is deprecated. Deprecated in Java

void
takeKeyEvents(boolean get)
void
triggerSearch(@NonNull String query, @Nullable Bundle appSearchData)
void
void
void
From android.content.ComponentCallbacks
void
From android.content.Context
boolean
bindIsolatedService(
    @NonNull Intent service,
    @NonNull Context.BindServiceFlags flags,
    @NonNull String instanceName,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindIsolatedService(
    @NonNull Intent service,
    int flags,
    @NonNull String instanceName,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindService(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    @NonNull Context.BindServiceFlags flags
)
boolean
bindService(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    int flags
)
boolean
bindService(
    @NonNull Intent service,
    @NonNull Context.BindServiceFlags flags,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindService(
    @NonNull Intent service,
    int flags,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindServiceAsUser(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    @NonNull Context.BindServiceFlags flags,
    @NonNull UserHandle user
)
boolean
bindServiceAsUser(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    int flags,
    @NonNull UserHandle user
)
int
int
@NonNull int[]
checkCallingOrSelfUriPermissions(
    @NonNull List<@NonNull Uri> uris,
    int modeFlags
)
int
int
checkCallingUriPermission(@NonNull Uri uri, int modeFlags)
@NonNull int[]
int
checkContentUriPermissionFull(
    @NonNull Uri uri,
    int pid,
    int uid,
    int modeFlags
)
int
checkPermission(@NonNull String permission, int pid, int uid)
int
int
checkUriPermission(@NonNull Uri uri, int pid, int uid, int modeFlags)
int
checkUriPermission(
    @Nullable Uri uri,
    @Nullable String readPermission,
    @Nullable String writePermission,
    int pid,
    int uid,
    int modeFlags
)
@NonNull int[]
checkUriPermissions(
    @NonNull List<@NonNull Uri> uris,
    int pid,
    int uid,
    int modeFlags
)
void

This method is deprecated. Deprecated in Java

@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
createDeviceContext(int deviceId)
@NonNull Context
@NonNull Context
@NonNull Context
createPackageContext(@NonNull String packageName, int flags)
@NonNull Context
createWindowContext(int type, @Nullable Bundle options)
@NonNull Context
createWindowContext(
    @NonNull Display display,
    int type,
    @Nullable Bundle options
)
@NonNull String[]
boolean
boolean
boolean
void
enforceCallingOrSelfPermission(
    @NonNull String permission,
    @Nullable String message
)
void
enforceCallingOrSelfUriPermission(
    @NonNull Uri uri,
    int modeFlags,
    @NonNull String message
)
void
enforceCallingPermission(
    @NonNull String permission,
    @Nullable String message
)
void
enforceCallingUriPermission(
    @NonNull Uri uri,
    int modeFlags,
    @NonNull String message
)
void
enforcePermission(
    @NonNull String permission,
    int pid,
    int uid,
    @Nullable String message
)
void
enforceUriPermission(
    @NonNull Uri uri,
    int pid,
    int uid,
    int modeFlags,
    @NonNull String message
)
void
enforceUriPermission(
    @Nullable Uri uri,
    @Nullable String readPermission,
    @Nullable String writePermission,
    int pid,
    int uid,
    int modeFlags,
    @Nullable String message
)
@NonNull String[]
final int
getColor(int id)
final @NonNull ColorStateList
@NonNull File
@NonNull File
getDir(@NonNull String name, int mode)
final @Nullable Drawable
getDrawable(int id)
@Nullable File
@NonNull File[]
@NonNull File
@NonNull SharedPreferences
getSharedPreferences(@NonNull String name, int mode)
final @NonNull String
getString(int resId)
final @NonNull String
getString(int resId, @NonNull Object... formatArgs)
@NonNull Object
final @NonNull T
<T extends Object> getSystemService(@NonNull Class<@NonNull T> serviceClass)
String
final @NonNull CharSequence
getText(int resId)
void
grantUriPermission(
    @NonNull String toPackage,
    @NonNull Uri uri,
    int modeFlags
)
boolean
moveDatabaseFrom(@NonNull Context sourceContext, @NonNull String name)
boolean
moveSharedPreferencesFrom(
    @NonNull Context sourceContext,
    @NonNull String name
)
final @NonNull TypedArray
final @NonNull TypedArray
obtainStyledAttributes(int resid, @NonNull int[] attrs)
final @NonNull TypedArray
final @NonNull TypedArray
obtainStyledAttributes(
    @Nullable AttributeSet set,
    @NonNull int[] attrs,
    int defStyleAttr,
    int defStyleRes
)
@NonNull FileInputStream
@NonNull FileOutputStream
openFileOutput(@NonNull String name, int mode)
@NonNull SQLiteDatabase
openOrCreateDatabase(
    @NonNull String name,
    int mode,
    @NonNull SQLiteDatabase.CursorFactory factory
)
@NonNull SQLiteDatabase
openOrCreateDatabase(
    @NonNull String name,
    int mode,
    @NonNull SQLiteDatabase.CursorFactory factory,
    @Nullable DatabaseErrorHandler errorHandler
)
@NonNull Drawable

This method is deprecated. Deprecated in Java

void
void
registerDeviceIdChangeListener(
    @NonNull Executor executor,
    @NonNull IntConsumer listener
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    int flags
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    @Nullable String broadcastPermission,
    @Nullable Handler scheduler
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    @Nullable String broadcastPermission,
    @Nullable Handler scheduler,
    int flags
)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
void
void
revokeUriPermission(@NonNull Uri uri, int modeFlags)
void
revokeUriPermission(
    @NonNull String targetPackage,
    @NonNull Uri uri,
    int modeFlags
)
void
void
sendBroadcast(@NonNull Intent intent, @Nullable String receiverPermission)
void
sendBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable Bundle options
)
void
void
sendBroadcastAsUser(
    @NonNull Intent intent,
    @NonNull UserHandle user,
    String receiverPermission
)
void
sendBroadcastWithMultiplePermissions(
    @NonNull Intent intent,
    @NonNull String[] receiverPermissions
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable Bundle options
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable Bundle options,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable String receiverAppOp,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)
void
sendOrderedBroadcastAsUser(
    @NonNull Intent intent,
    @NonNull UserHandle user,
    @Nullable String receiverPermission,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
sendStickyOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)

This method is deprecated. Deprecated in Java

void
sendStickyOrderedBroadcastAsUser(
    @NonNull Intent intent,
    @NonNull UserHandle user,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)

This method is deprecated. Deprecated in Java

void
setTheme(int resid)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
startActivities(@NonNull Intent[] intents)
void
startActivities(@NonNull Intent[] intents, @Nullable Bundle options)
void
void
@Nullable ComponentName
boolean
startInstrumentation(
    @NonNull ComponentName className,
    @Nullable String profileFile,
    @Nullable Bundle arguments
)
void
startIntentSender(
    @NonNull IntentSender intent,
    @Nullable Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags
)
void
startIntentSender(
    @NonNull IntentSender intent,
    @Nullable Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    @Nullable Bundle options
)
@Nullable ComponentName
boolean
void
void
void
void
void
updateServiceGroup(
    @NonNull ServiceConnection conn,
    int group,
    int importance
)
From android.view.ContextThemeWrapper
From android.content.ContextWrapper
void
@NonNull Context
@NonNull ApplicationInfo
@NonNull AttributionSource
@Nullable String
@NonNull Context
@NonNull File
@NonNull ClassLoader
@NonNull File
@NonNull ContentResolver
@NonNull File
int
@Nullable Display
@Nullable File
@NonNull File[]
@NonNull File[]
@NonNull File
@NonNull Executor
@NonNull Looper
@NonNull File
@NonNull File
@NonNull File[]
@NonNull String
@NonNull String
@NonNull PackageManager
@NonNull String
@NonNull String
@Nullable ContextParams
@NonNull Drawable

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

boolean
boolean
boolean
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    int initialCode,
    @Nullable String receiverPermission,
    @Nullable String receiverAppOp,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    @Nullable String initialData,
    @Nullable Bundle initialExtras,
    @Nullable Bundle options
)
From android.view.KeyEvent.Callback
boolean
onKeyDown(int keyCode, @NonNull KeyEvent event)
boolean
onKeyLongPress(int keyCode, @NonNull KeyEvent event)
boolean
onKeyMultiple(int keyCode, int repeatCount, @NonNull KeyEvent event)
boolean
onKeyUp(int keyCode, @NonNull KeyEvent event)
From android.view.LayoutInflater.Factory
@Nullable View
onCreateView(
    @NonNull String name,
    @NonNull Context context,
    @NonNull AttributeSet attrs
)
From android.view.LayoutInflater.Factory2
@Nullable View
onCreateView(
    @Nullable View parent,
    @NonNull String name,
    @NonNull Context context,
    @NonNull AttributeSet attrs
)
From android.view.View.OnCreateContextMenuListener
void
From android.view.Window.Callback

Public constructors

ComponentActivity

Added in 1.0.0
public ComponentActivity()

ComponentActivity

Added in 1.0.0
@ContentView
public 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).

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

addContentView

public void addContentView(View view, ViewGroup.LayoutParams params)

addMenuProvider

Added in 1.4.0
public void addMenuProvider(@NonNull MenuProvider provider)

Adds the given MenuProvider to this MenuHost. If using this method, you must manually remove the provider when necessary.

Parameters
@NonNull MenuProvider provider

the MenuProvider to be added

addMenuProvider

Added in 1.4.0
public void addMenuProvider(
    @NonNull MenuProvider provider,
    @NonNull LifecycleOwner owner
)

Adds the given MenuProvider to this MenuHost. This MenuProvider will be removed once the given LifecycleOwner receives an Lifecycle.Event.ON_DESTROY event.

Parameters
@NonNull MenuProvider provider

the MenuProvider to be added

@NonNull LifecycleOwner owner

the Lifecycle owner whose state will determine the removal of the provider

addMenuProvider

Added in 1.4.0
public 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. This MenuProvider will be removed once the given LifecycleOwner goes down from the given Lifecycle.State.

Parameters
@NonNull MenuProvider provider

the MenuProvider to be added

@NonNull LifecycleOwner owner

the Lifecycle owner whose state will be used for automated addition/removal

@NonNull Lifecycle.State state

the Lifecycle.State to check for automated addition/removal

addOnConfigurationChangedListener

Added in 1.5.0
public final void addOnConfigurationChangedListener(
    @NonNull Consumer<@NonNull Configuration> listener
)

Add a new listener that will get a callback associated with ComponentCallbacks.onConfigurationChanged with the new Configuration.

Parameters
@NonNull Consumer<@NonNull Configuration> listener

The listener that should be called whenever {ComponentCallbacks.onConfigurationChanged was called.

addOnContextAvailableListener

public final void addOnContextAvailableListener(
    @NonNull OnContextAvailableListener listener
)

{@inheritDoc}

Any listener added here will receive a callback as part of super.onCreate(), but importantly before any other logic is done (including calling through to the framework Activity.onCreate with the exception of restoring the state of the savedStateRegistry for use in your listener.

addOnMultiWindowModeChangedListener

Added in 1.5.0
public final void addOnMultiWindowModeChangedListener(
    @NonNull Consumer<@NonNull MultiWindowModeChangedInfo> listener
)

Add a new listener that will get a callback associated with Activity.onMultiWindowModeChanged with the new MultiWindowModeChangedInfo.

Parameters
@NonNull Consumer<@NonNull MultiWindowModeChangedInfo> listener

The listener that should be called whenever Activity#onMultiWindowModeChanged was called.

addOnNewIntentListener

Added in 1.5.0
public final void addOnNewIntentListener(@NonNull Consumer<@NonNull Intent> listener)

Add a new listener that will get a callback associated with Activity.onNewIntent with the new Intent.

Parameters
@NonNull Consumer<@NonNull Intent> listener

The listener that should be called whenever android.app.Activity#onNewIntent was called.

addOnPictureInPictureModeChangedListener

Added in 1.5.0
public final void addOnPictureInPictureModeChangedListener(
    @NonNull Consumer<@NonNull PictureInPictureModeChangedInfo> listener
)

Add a new listener that will get a callback associated with Activity.onPictureInPictureModeChanged with the new PictureInPictureModeChangedInfo.

Parameters
@NonNull Consumer<@NonNull PictureInPictureModeChangedInfo> listener

The listener that should be called whenever Activity.onPictureInPictureModeChanged was called.

addOnPictureInPictureUiStateChangedListener

public final void addOnPictureInPictureUiStateChangedListener(
    @NonNull Consumer<@NonNull PictureInPictureUiStateCompat> listener
)

Add a new listener that will get a callback associated with Activity.onPictureInPictureUiStateChanged with the new PictureInPictureUiStateCompat.

Parameters
@NonNull Consumer<@NonNull PictureInPictureUiStateCompat> listener

The listener that should be called whenever Activity.onPictureInPictureUiStateChanged was called.

addOnTrimMemoryListener

Added in 1.5.0
public final void addOnTrimMemoryListener(@NonNull Consumer<@NonNull Integer> listener)

Add a new listener that will get a callback associated with ComponentCallbacks2.onTrimMemory with the int representing the level of trimming.

Parameters
@NonNull Consumer<@NonNull Integer> listener

The listener that should be called whenever ComponentCallbacks2.onTrimMemory was called.

addOnUserLeaveHintListener

Added in 1.9.0
public final void addOnUserLeaveHintListener(@NonNull Runnable listener)

Add a new listener that will get a callback associated with Activity.onUserLeaveHint

Parameters
@NonNull Runnable listener

The listener that should be called whenever Activity.onUserLeaveHint was called.

enterPictureInPictureMode

public final void enterPictureInPictureMode(@NonNull PictureInPictureParamsCompat params)

Available since API 24 in the framework Activity class, puts the activity in picture-in-picture mode if possible in the current system state. Any prior calls to setPictureInPictureParams will still apply when entering picture-in-picture through this call.

getActivityResultRegistry

public final @NonNull ActivityResultRegistry getActivityResultRegistry()

Get the ActivityResultRegistry associated with this activity.

getDefaultViewModelCreationExtras

@CallSuper
public @NonNull CreationExtras getDefaultViewModelCreationExtras()

{@inheritDoc}

The extras of getIntent when this is first called will be used as the defaults to any androidx.lifecycle.SavedStateHandle passed to a view model created using this extra.

getDefaultViewModelProviderFactory

Added in 1.1.0
public final @NonNull ViewModelProvider.Factory getDefaultViewModelProviderFactory()

getFullyDrawnReporter

public final @NonNull FullyDrawnReporter getFullyDrawnReporter()

Retrieve the FullyDrawnReporter that should handle the independent parts of the UI that separately report that they are fully drawn.

getLastCustomNonConfigurationInstance

Added in 1.0.0
Deprecated in 1.0.0
public Object getLastCustomNonConfigurationInstance()

Return the value previously returned from onRetainCustomNonConfigurationInstance.

getLifecycle

Added in 1.0.0
public @NonNull Lifecycle getLifecycle()

{@inheritDoc}

Overriding this method is no longer supported and this method will be made final in a future version of ComponentActivity. If you do override this method, you must:

  1. Return an instance of LifecycleRegistry

  2. Lazily initialize your LifecycleRegistry object when this is first called.

Note that this method will be called in the super classes' constructor, before any field initialization or object state creation is complete.

getNavigationEventDispatcher

Added in 1.12.0
public @NonNull NavigationEventDispatcher getNavigationEventDispatcher()

Lazily provides a NavigationEventDispatcher for back navigation handling, including support for predictive back gestures introduced in Android 13 (API 33+).

This dispatcher acts as the central point for back navigation events. When a navigation event occurs (e.g., a back gesture), it safely invokes ComponentActivity.onBackPressed.

getOnBackPressedDispatcher

public final @NonNull OnBackPressedDispatcher getOnBackPressedDispatcher()

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

Returns
@NonNull OnBackPressedDispatcher

The OnBackPressedDispatcher associated with this ComponentActivity.

getSavedStateRegistry

Added in 1.0.0
public final @NonNull SavedStateRegistry getSavedStateRegistry()

getViewModelStore

Added in 1.0.0
public @NonNull ViewModelStore getViewModelStore()

Returns the ViewModelStore associated with this activity

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

Throws
IllegalStateException

if called before the Activity is attached to the Application instance i.e., before onCreate()

initializeViewTreeOwners

Added in 1.8.0
@CallSuper
public void initializeViewTreeOwners()

Sets the view tree owners before setting the content view so that the inflation process and attach listeners will see them already present.

invalidateMenu

Added in 1.4.0
public void invalidateMenu()

Invalidates the android.view.Menu to ensure that what is displayed matches the current internal state of the menu. This should be called whenever the state of the menu is changed, such as items being removed or disabled based on some user event.

onBackPressed

Added in 1.6.0
@MainThread
@CallSuper
public void onBackPressed()

Called when the activity has detected the user's press of the back key. The onBackPressedDispatcher will be given a chance to handle the back button before the default behavior of android.app.Activity.onBackPressed is invoked.

onConfigurationChanged

@CallSuper
public void onConfigurationChanged(@NonNull Configuration newConfig)

{@inheritDoc}

Dispatches this call to all listeners added via addOnConfigurationChangedListener.

onCreatePanelMenu

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

onMenuItemSelected

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

onMultiWindowModeChanged

Added in 1.5.0
@CallSuper
public void onMultiWindowModeChanged(boolean isInMultiWindowMode)

{@inheritDoc}

Dispatches this call to all listeners added via addOnMultiWindowModeChangedListener.

onMultiWindowModeChanged

@RequiresApi(api = 26)
@CallSuper
public void onMultiWindowModeChanged(
    boolean isInMultiWindowMode,
    @NonNull Configuration newConfig
)

{@inheritDoc}

Dispatches this call to all listeners added via addOnMultiWindowModeChangedListener.

onPanelClosed

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

onPictureInPictureModeChanged

Added in 1.5.0
@CallSuper
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode)

{@inheritDoc}

Dispatches this call to all listeners added via addOnPictureInPictureModeChangedListener.

onPictureInPictureModeChanged

@RequiresApi(api = 26)
@CallSuper
public void onPictureInPictureModeChanged(
    boolean isInPictureInPictureMode,
    @NonNull Configuration newConfig
)

{@inheritDoc}

Dispatches this call to all listeners added via addOnPictureInPictureModeChangedListener.

onPictureInPictureUiStateChanged

@RequiresApi(api = 31)
@CallSuper
public void onPictureInPictureUiStateChanged(
    @NonNull PictureInPictureUiState pipState
)

{@inheritDoc}

onPreparePanel

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

onRequestPermissionsResult

Added in 1.2.0
Deprecated in 1.2.0
@CallSuper
public void onRequestPermissionsResult(
    int requestCode,
    @NonNull String[] permissions,
    @NonNull int[] grantResults
)

{@inheritDoc}

onRetainCustomNonConfigurationInstance

Added in 1.0.0
Deprecated in 1.0.0
public Object onRetainCustomNonConfigurationInstance()

Use this instead of onRetainNonConfigurationInstance. Retrieve later with lastCustomNonConfigurationInstance.

onRetainNonConfigurationInstance

Added in 1.0.0
public final Object onRetainNonConfigurationInstance()

Retain all appropriate non-config state. You can NOT override this yourself! Use a androidx.lifecycle.ViewModel if you want to retain your own non config state.

onTrimMemory

@CallSuper
public void onTrimMemory(int level)

{@inheritDoc}

Dispatches this call to all listeners added via addOnTrimMemoryListener.

peekAvailableContext

public Context peekAvailableContext()

Get the Context if it is currently available. If this returns null, you can use addOnContextAvailableListener to receive a callback for when it available.

Returns
Context

the Context if it is currently available.

registerForActivityResult

public final @NonNull ActivityResultLauncher<@NonNull I> <I extends Object, O extends Object> registerForActivityResult(
    @NonNull ActivityResultContract<@NonNull I, @NonNull O> contract,
    @NonNull ActivityResultCallback<@NonNull O> callback
)

Register a request to start an activity for result, designated by the given contract.

This creates a record in the registry associated with this caller, managing request code, as well as conversions to/from Intent under the hood.

This must be called unconditionally, as part of initialization path, typically as a field initializer of an Activity or Fragment.

Parameters
<I extends Object>

the type of the input(if any) required to call the activity

<O extends Object>

the type of output returned as an activity result

@NonNull ActivityResultContract<@NonNull I, @NonNull O> contract

the contract, specifying conversions to/from Intents

@NonNull ActivityResultCallback<@NonNull O> callback

the callback to be called on the main thread when activity result is available

Returns
@NonNull ActivityResultLauncher<@NonNull I>

the launcher that can be used to start the activity or dispose of the prepared call.

registerForActivityResult

public final @NonNull ActivityResultLauncher<@NonNull I> <I extends Object, O extends Object> registerForActivityResult(
    @NonNull ActivityResultContract<@NonNull I, @NonNull O> contract,
    @NonNull ActivityResultRegistry registry,
    @NonNull ActivityResultCallback<@NonNull O> callback
)

Register a request to start an activity for result, designated by the given contract.

This creates a record in the given registry, managing request code, as well as conversions to/from Intent under the hood.

This must be called unconditionally, as part of initialization path, typically as a field initializer of an Activity or Fragment.

Parameters
<I extends Object>

the type of the input(if any) required to call the activity

<O extends Object>

the type of output returned as an activity result

@NonNull ActivityResultContract<@NonNull I, @NonNull O> contract

the contract, specifying conversions to/from Intents

@NonNull ActivityResultRegistry registry

the registry where to hold the record.

@NonNull ActivityResultCallback<@NonNull O> callback

the callback to be called on the main thread when activity result is available

Returns
@NonNull ActivityResultLauncher<@NonNull I>

the launcher that can be used to start the activity or dispose of the prepared call.

removeMenuProvider

Added in 1.4.0
public void removeMenuProvider(@NonNull MenuProvider provider)

Removes the given MenuProvider from this MenuHost.

Parameters
@NonNull MenuProvider provider

the MenuProvider to be removed

removeOnConfigurationChangedListener

Added in 1.5.0
public final void removeOnConfigurationChangedListener(
    @NonNull Consumer<@NonNull Configuration> listener
)

Remove a previously added listener. It will not receive any future callbacks.

Parameters
@NonNull Consumer<@NonNull Configuration> listener

The listener previously added with addOnConfigurationChangedListener that should be removed.

removeOnContextAvailableListener

public final void removeOnContextAvailableListener(
    @NonNull OnContextAvailableListener listener
)

Remove a OnContextAvailableListener previously added via addOnContextAvailableListener.

Parameters
@NonNull OnContextAvailableListener listener

The listener that should be removed.

removeOnMultiWindowModeChangedListener

Added in 1.5.0
public final void removeOnMultiWindowModeChangedListener(
    @NonNull Consumer<@NonNull MultiWindowModeChangedInfo> listener
)

Remove a previously added listener. It will not receive any future callbacks.

Parameters
@NonNull Consumer<@NonNull MultiWindowModeChangedInfo> listener

The listener previously added with addOnMultiWindowModeChangedListener that should be removed.

removeOnNewIntentListener

Added in 1.5.0
public final void removeOnNewIntentListener(@NonNull Consumer<@NonNull Intent> listener)

Remove a previously added listener. It will not receive any future callbacks.

Parameters
@NonNull Consumer<@NonNull Intent> listener

The listener previously added with addOnNewIntentListener that should be removed.

removeOnPictureInPictureModeChangedListener

Added in 1.5.0
public final void removeOnPictureInPictureModeChangedListener(
    @NonNull Consumer<@NonNull PictureInPictureModeChangedInfo> listener
)

Remove a previously added listener. It will not receive any future callbacks.

Parameters
@NonNull Consumer<@NonNull PictureInPictureModeChangedInfo> listener

The listener previously added with addOnPictureInPictureModeChangedListener that should be removed.

removeOnPictureInPictureUiStateChangedListener

public final void removeOnPictureInPictureUiStateChangedListener(
    @NonNull Consumer<@NonNull PictureInPictureUiStateCompat> listener
)

Remove a previously added listener. It will not receive any future callbacks.

Parameters
@NonNull Consumer<@NonNull PictureInPictureUiStateCompat> listener

The listener previously added with addOnPictureInPictureUiStateChangedListener that should be removed.

removeOnTrimMemoryListener

Added in 1.5.0
public final void removeOnTrimMemoryListener(@NonNull Consumer<@NonNull Integer> listener)

Remove a previously added listener. It will not receive any future callbacks.

Parameters
@NonNull Consumer<@NonNull Integer> listener

The listener previously added with .addOnTrimMemoryListener that should be removed.

removeOnUserLeaveHintListener

Added in 1.9.0
public final void removeOnUserLeaveHintListener(@NonNull Runnable listener)

Remove a previously added listener. It will not receive any future callbacks.

Parameters
@NonNull Runnable listener

The listener previously added with addOnUserLeaveHintListener that should be removed.

reportFullyDrawn

public void reportFullyDrawn()

setContentView

public void setContentView(@LayoutRes int layoutResID)

setContentView

public void setContentView(View view)

setContentView

public void setContentView(View view, ViewGroup.LayoutParams params)

setPictureInPictureParams

public final void setPictureInPictureParams(@NonNull PictureInPictureParamsCompat params)

Available since API 26 in the framework Activity class, updates the properties of the picture-in-picture activity, or sets it to be used later when enterPictureInPictureMode is called

Parameters
@NonNull PictureInPictureParamsCompat params

PictureInPictureParams to use for picture-in-picture mode.

startActivityForResult

Added in 1.2.0
Deprecated in 1.2.0
public void startActivityForResult(@NonNull Intent intent, int requestCode)

{@inheritDoc}

startActivityForResult

Added in 1.2.0
Deprecated in 1.2.0
public void startActivityForResult(
    @NonNull Intent intent,
    int requestCode,
    Bundle options
)

{@inheritDoc}

startIntentSenderForResult

Added in 1.2.0
Deprecated in 1.2.0
public void startIntentSenderForResult(
    @NonNull IntentSender intent,
    int requestCode,
    Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags
)

{@inheritDoc}

startIntentSenderForResult

Added in 1.2.0
Deprecated in 1.2.0
public void startIntentSenderForResult(
    @NonNull IntentSender intent,
    int requestCode,
    Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    Bundle options
)

{@inheritDoc}

Protected methods

onActivityResult

Added in 1.2.0
Deprecated in 1.2.0
@CallSuper
protected void onActivityResult(int requestCode, int resultCode, Intent data)

{@inheritDoc}

onCreate

protected void onCreate(Bundle savedInstanceState)

{@inheritDoc}

If your ComponentActivity is annotated with ContentView, this will call setContentView for you.

onNewIntent

@CallSuper
protected void onNewIntent(@NonNull Intent intent)

{@inheritDoc}

Dispatches this call to all listeners added via addOnNewIntentListener.

onSaveInstanceState

@CallSuper
protected void onSaveInstanceState(@NonNull Bundle outState)

onUserLeaveHint

@CallSuper
protected void onUserLeaveHint()

{@inheritDoc}

Dispatches this call to all listeners added via addOnUserLeaveHintListener.

Extension functions

ActivityViewModelLazyKt.viewModels

@MainThread
public final @NonNull Lazy<@NonNull VM> <VM extends ViewModel> ActivityViewModelLazyKt.viewModels(
    @NonNull ComponentActivity receiver,
    Function0<@NonNull CreationExtras> extrasProducer,
    Function0<@NonNull ViewModelProvider.Factory> factoryProducer
)

Returns a Lazy delegate to access the ComponentActivity's ViewModel, if factoryProducer is specified then ViewModelProvider.Factory returned by it will be used to create ViewModel first time.

class MyComponentActivity : ComponentActivity() {
val viewmodel: MyViewModel by viewModels()
}

This property can be accessed only after the Activity is attached to the Application, and access prior to that will result in IllegalArgumentException.

EdgeToEdge.enableEdgeToEdge

public final void EdgeToEdge.enableEdgeToEdge(
    @NonNull ComponentActivity receiver,
    @NonNull SystemBarStyle statusBarStyle,
    @NonNull SystemBarStyle navigationBarStyle
)

Enables the edge-to-edge display for this ComponentActivity.

To set it up with the default style, call this method in your Activity's onCreate method:

    override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
...
}

The default style configures the system bars with a transparent background when contrast can be enforced by the system (API 29 or above). On older platforms (which only have 3-button/2-button navigation modes), an equivalent scrim is applied to ensure contrast with the system bars.

See SystemBarStyle for more customization options.

Parameters
@NonNull SystemBarStyle statusBarStyle

The SystemBarStyle for the status bar.

@NonNull SystemBarStyle navigationBarStyle

The SystemBarStyle for the navigation bar.