ComponentActivity


open class ComponentActivity : Activity, LifecycleOwner, ContextAware, ViewModelStoreOwner, HasDefaultViewModelProviderFactory, SavedStateRegistryOwner, OnBackPressedDispatcherOwner, ActivityResultRegistryOwner, ActivityResultCaller, OnConfigurationChangedProvider, OnTrimMemoryProvider, OnNewIntentProvider, OnMultiWindowModeChangedProvider, OnPictureInPictureModeChangedProvider, OnUserLeaveHintProvider, MenuHost, FullyDrawnReporterOwner

Known direct subclasses
FragmentActivity

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

PreviewActivity

Activity used to run @Composable previews from Android Studio.

SdkActivity

Activity to start for SDKs running locally.

SubspaceTestingActivity

Custom test class that should be used for testing SubspaceComposable content.

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

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

Public functions

open Unit
open Unit

Adds the given MenuProvider to this MenuHost.

open Unit

Adds the given MenuProvider to this MenuHost.

open Unit
addMenuProvider(
    provider: MenuProvider,
    owner: LifecycleOwner,
    state: Lifecycle.State
)

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

final Unit

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

final Unit

{@inheritDoc}

final Unit

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

final Unit

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

final Unit

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

final Unit

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

final Unit

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

open Unit

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

open Unit

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

open Unit

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

open Unit

{@inheritDoc}

open Boolean
onCreatePanelMenu(featureId: Int, menu: Menu)
open Boolean
onMenuItemSelected(featureId: Int, item: MenuItem)
open Unit

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

open Unit
@RequiresApi(api = 26)
@CallSuper
onMultiWindowModeChanged(
    isInMultiWindowMode: Boolean,
    newConfig: Configuration
)

{@inheritDoc}

open Unit
onPanelClosed(featureId: Int, menu: Menu)
open Unit
@CallSuper
onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean)

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

open Unit
@RequiresApi(api = 26)
@CallSuper
onPictureInPictureModeChanged(
    isInPictureInPictureMode: Boolean,
    newConfig: Configuration
)

{@inheritDoc}

open Boolean
onPreparePanel(featureId: Int, view: View?, menu: Menu)
open Unit
@CallSuper
onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<String>,
    grantResults: IntArray
)

This function 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.

open Any?

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

final Any?

Retain all appropriate non-config state.

open Unit

{@inheritDoc}

open Context?

Get the Context if it is currently available.

final ActivityResultLauncher<I>
<I : Any?, O : Any?> registerForActivityResult(
    contract: ActivityResultContract<I, O>,
    callback: ActivityResultCallback<O>
)

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

final ActivityResultLauncher<I>
<I : Any?, O : Any?> registerForActivityResult(
    contract: ActivityResultContract<I, O>,
    registry: ActivityResultRegistry,
    callback: ActivityResultCallback<O>
)

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

open Unit

Removes the given MenuProvider from this MenuHost.

final Unit

Remove a previously added listener.

final Unit

Remove a OnContextAvailableListener previously added via addOnContextAvailableListener.

final Unit

Remove a previously added listener.

final Unit

Remove a previously added listener.

final Unit

Remove a previously added listener.

final Unit

Remove a previously added listener.

final Unit

Remove a previously added listener.

open Unit
open Unit
setContentView(layoutResID: @LayoutRes Int)
open Unit
open Unit
open Unit
startActivityForResult(intent: Intent, requestCode: Int)

This function 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.

open Unit
startActivityForResult(intent: Intent, requestCode: Int, options: Bundle?)

This function 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.

open Unit
startIntentSenderForResult(
    intent: IntentSender,
    requestCode: Int,
    fillInIntent: Intent?,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int
)

This function 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.

open Unit
startIntentSenderForResult(
    intent: IntentSender,
    requestCode: Int,
    fillInIntent: Intent?,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int,
    options: Bundle?
)

This function 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 functions

open Unit
@CallSuper
onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)

This function 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.

open Unit
onCreate(savedInstanceState: Bundle?)

{@inheritDoc}

open Unit

{@inheritDoc}

open Unit
open Unit

{@inheritDoc}

Public properties

final ActivityResultRegistry

Get the ActivityResultRegistry associated with this activity.

open CreationExtras
open ViewModelProvider.Factory
open FullyDrawnReporter

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

open Any?
open Lifecycle

{@inheritDoc}

final OnBackPressedDispatcher

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

final SavedStateRegistry
open ViewModelStore

Extension functions

Unit
ComponentActivity.setSubspaceContent(
    session: Session?,
    enableXrForTesting: Boolean,
    content: @Composable @SubspaceComposable () -> Unit
)

Composes the provided composable content into this activity's subspace.

inline Lazy<VM>
@MainThread
<VM : ViewModel> ComponentActivity.viewModels(
    noinline extrasProducer: (() -> CreationExtras)?,
    noinline factoryProducer: (() -> ViewModelProvider.Factory)?
)

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.

Unit
ComponentActivity.setContent(
    parent: CompositionContext?,
    content: @Composable () -> Unit
)

Composes the given composable into the given activity.

Unit
ComponentActivity.enableEdgeToEdge(
    statusBarStyle: SystemBarStyle,
    navigationBarStyle: SystemBarStyle
)

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

Inherited functions

From android.app.Activity
open Unit
open Unit
open Unit
open Unit
open PendingIntent
createPendingResult(p0: Int, p1: Intent, p2: Int)
Unit

This function is deprecated. Deprecated in Java

Unit
open Boolean
open Boolean
open Boolean
open Boolean
open Unit
dump(p0: String, p1: FileDescriptor?, p2: PrintWriter, p3: Array<String>?)
open Unit

This function is deprecated. Deprecated in Java

open Boolean
open T
<T : View> findViewById(p0: Int)
open Unit
open Unit
open Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
open Unit

This function is deprecated. Deprecated in Java

open ActionBar?
Application
open ComponentName?
open String?
open Int
open ComponentName
open Scene
open TransitionManager
open View?
open FragmentManager

This function is deprecated. Deprecated in Java

open Intent
open Any?
open String?
open Int
open LayoutInflater
open LoaderManager

This function is deprecated. Deprecated in Java

open String
open Int
MediaController
open MenuInflater
open OnBackInvokedDispatcher
Activity
open Intent?
open SharedPreferences
open Uri?
open Int
SearchEvent
SplashScreen
open Any
open Int
CharSequence
Int
open VoiceInteractor
Int
open Window
open WindowManager
open Boolean
open Unit
open Boolean
open Boolean
Boolean
open Boolean
open Boolean
open Boolean
open Boolean
open Boolean
open Boolean
open Boolean
open Boolean
open Boolean
open Boolean
Cursor
managedQuery(
    p0: Uri,
    p1: Array<String>,
    p2: String,
    p3: Array<String>,
    p4: String
)

This function is deprecated. Deprecated in Java

open Boolean
open Boolean
open Boolean

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
open Unit
open Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
open Boolean
open Unit
open Unit
open Unit
onCreateContextMenu(
    p0: ContextMenu,
    p1: View,
    p2: ContextMenu.ContextMenuInfo
)
open CharSequence?
open Dialog

This function is deprecated. Deprecated in Java

open Dialog?

This function is deprecated. Deprecated in Java

open Unit
open Boolean
open View?
open Boolean

This function is deprecated. Deprecated in Java

open View?
open View?
onCreateView(p0: View?, p1: String, p2: Context, p3: AttributeSet)
open Unit
open Unit
open Unit
open Boolean
open Unit
open Boolean
onKeyDown(p0: Int, p1: KeyEvent)
open Boolean
open Boolean
onKeyMultiple(p0: Int, p1: Int, p2: KeyEvent)
open Boolean
open Boolean
onKeyUp(p0: Int, p1: KeyEvent)
open Unit
open Unit
open Unit
open Boolean
onMenuOpened(p0: Int, p1: Menu)
open Boolean
open Boolean

This function is deprecated. Deprecated in Java

open Boolean
open Unit
open Unit
open Unit
onPerformDirectAction(
    p0: String,
    p1: Bundle,
    p2: CancellationSignal,
    p3: Consumer<Bundle>
)
open Boolean
open Unit
open Unit
open Unit
open Unit
open Unit

This function is deprecated. Deprecated in Java

open Unit
onPrepareDialog(p0: Int, p1: Dialog, p2: Bundle)

This function is deprecated. Deprecated in Java

open Unit
open Boolean
open Unit
open Unit
open Unit
onProvideKeyboardShortcuts(
    p0: MutableList<KeyboardShortcutGroup>,
    p1: Menu?,
    p2: Int
)
open Uri
open Unit
open Unit
open Unit
open Unit
open Unit
open Boolean
open Boolean
open Unit
open Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
open Boolean
open Boolean
open Unit
open Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
open ActionMode?
open ActionMode?
open Unit
open Unit
open Unit
open Unit
overrideActivityTransition(p0: Int, p1: Int, p2: Int, p3: Int)
open Unit

This function is deprecated. Deprecated in Java

open Unit
overridePendingTransition(p0: Int, p1: Int, p2: Int)

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
open Unit
open Unit
open Unit
open Boolean
Unit

This function is deprecated. Deprecated in Java

open DragAndDropPermissions
open Unit
Unit
Unit
open Boolean

This function is deprecated. Deprecated in Java

Boolean
T
<T : View> requireViewById(p0: Int)
Unit
open Unit
open Unit
Unit
open Unit
open Unit
Unit
Unit
Unit
Unit
open Unit
open Unit
open Unit
open Unit
open Unit
Unit
open Unit
Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
Unit
Unit
setResult(p0: Int, p1: Intent)
Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
open Unit
open Unit
open Unit
open Unit

This function is deprecated. Deprecated in Java

open Boolean
open Unit
open Unit
Unit
open Unit
open Boolean
open Boolean
open Boolean
open Boolean
Unit

This function is deprecated. Deprecated in Java

Boolean
showDialog(p0: Int, p1: Bundle)

This function is deprecated. Deprecated in Java

open Unit
open ActionMode?
open ActionMode?
open Unit
open Unit
open Unit
open Unit
open Unit

This function is deprecated. Deprecated in Java

open Unit
startActivityFromChild(p0: Activity, p1: Intent, p2: Int, p3: Bundle?)

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
startActivityFromFragment(p0: Fragment, p1: Intent, p2: Int, p3: Bundle?)

This function is deprecated. Deprecated in Java

open Boolean
open Boolean
startActivityIfNeeded(p0: Intent, p1: Int, p2: Bundle?)
open Unit
startIntentSender(p0: IntentSender, p1: Intent?, p2: Int, p3: Int, p4: Int)
open Unit
startIntentSender(
    p0: IntentSender,
    p1: Intent?,
    p2: Int,
    p3: Int,
    p4: Int,
    p5: Bundle?
)
open Unit
startIntentSenderFromChild(
    p0: Activity,
    p1: IntentSender,
    p2: Int,
    p3: Intent,
    p4: Int,
    p5: Int,
    p6: Int
)

This function is deprecated. Deprecated in Java

open Unit
startIntentSenderFromChild(
    p0: Activity,
    p1: IntentSender,
    p2: Int,
    p3: Intent,
    p4: Int,
    p5: Int,
    p6: Int,
    p7: Bundle?
)

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit

This function is deprecated. Deprecated in Java

open Boolean
open Boolean
open Unit
open Unit
startSearch(p0: String?, p1: Boolean, p2: Bundle?, p3: Boolean)
open Unit
open Unit
open Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
open Unit
open Unit
open Unit
From android.content.Context
From android.view.ContextThemeWrapper
From android.content.ContextWrapper
open Boolean
bindIsolatedService(
    p0: Intent,
    p1: Int,
    p2: String,
    p3: Executor,
    p4: ServiceConnection
)
open Boolean
bindService(
    p0: Intent,
    p1: ServiceConnection,
    p2: Context.BindServiceFlags
)
open Boolean
open Boolean
bindService(
    p0: Intent,
    p1: Context.BindServiceFlags,
    p2: Executor,
    p3: ServiceConnection
)
open Boolean
bindService(p0: Intent, p1: Int, p2: Executor, p3: ServiceConnection)
open Boolean
bindServiceAsUser(
    p0: Intent,
    p1: ServiceConnection,
    p2: Context.BindServiceFlags,
    p3: UserHandle
)
open Boolean
open Int
open Int
open IntArray
open Int
open Int
open IntArray
open Int
checkPermission(p0: String, p1: Int, p2: Int)
open Int
open Int
checkUriPermission(p0: Uri, p1: Int, p2: Int, p3: Int)
open Int
checkUriPermission(p0: Uri?, p1: String?, p2: String?, p3: Int, p4: Int, p5: Int)
open IntArray
checkUriPermissions(p0: MutableList<Uri>, p1: Int, p2: Int, p3: Int)
open Unit

This function is deprecated. Deprecated in Java

open Context
open Context
open Context
open Context
open Context
open Context
open Context
open Context
open Context
open Context
createWindowContext(p0: Display, p1: Int, p2: Bundle?)
open Array<String>
open Boolean
open Boolean
open Boolean
open Unit
open Unit
open Unit
open Unit
open Unit
enforcePermission(p0: String, p1: Int, p2: Int, p3: String?)
open Unit
enforceUriPermission(p0: Uri, p1: Int, p2: Int, p3: Int, p4: String)
open Unit
enforceUriPermission(
    p0: Uri?,
    p1: String?,
    p2: String?,
    p3: Int,
    p4: Int,
    p5: Int,
    p6: String?
)
open Array<String>
open Context
open ApplicationInfo
open AttributionSource
open String?
open Context
open File
open ClassLoader
open File
open ContentResolver
open File
open File
open Int
open File
getDir(p0: String, p1: Int)
open Display?
open File?
open Array<File>
open File?
open Array<File>
open Array<File>
open File
open File
open Executor
open Looper
open File
open File
open Array<File>
open String
open String
open PackageManager
open String
open String
open ContextParams?
open SharedPreferences
open String?
open Drawable

This function is deprecated. Deprecated in Java

open Int

This function is deprecated. Deprecated in Java

open Int

This function is deprecated. Deprecated in Java

open Unit
grantUriPermission(p0: String, p1: Uri, p2: Int)
open Boolean
open Boolean
open Boolean
open Boolean
open Boolean
open FileInputStream
open FileOutputStream
open SQLiteDatabase
open SQLiteDatabase
openOrCreateDatabase(
    p0: String,
    p1: Int,
    p2: SQLiteDatabase.CursorFactory,
    p3: DatabaseErrorHandler?
)
open Drawable

This function is deprecated. Deprecated in Java

open Unit
open Intent?
open Intent?
open Intent?
registerReceiver(
    p0: BroadcastReceiver?,
    p1: IntentFilter,
    p2: String?,
    p3: Handler?
)
open Intent?
registerReceiver(
    p0: BroadcastReceiver?,
    p1: IntentFilter,
    p2: String?,
    p3: Handler?,
    p4: Int
)
open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
revokeUriPermission(p0: String, p1: Uri, p2: Int)
open Unit
open Unit
open Unit
sendBroadcast(p0: Intent, p1: String?, p2: Bundle?)
open Unit
open Unit
open Unit
open Unit
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: String?,
    p2: BroadcastReceiver?,
    p3: Handler?,
    p4: Int,
    p5: String?,
    p6: Bundle?
)
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: String?,
    p2: Bundle?,
    p3: BroadcastReceiver?,
    p4: Handler?,
    p5: Int,
    p6: String?,
    p7: Bundle?
)
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: String?,
    p2: String?,
    p3: BroadcastReceiver?,
    p4: Handler?,
    p5: Int,
    p6: String?,
    p7: Bundle?
)
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: Int,
    p2: String?,
    p3: String?,
    p4: BroadcastReceiver?,
    p5: Handler?,
    p6: String?,
    p7: Bundle?,
    p8: Bundle?
)
open Unit
sendOrderedBroadcastAsUser(
    p0: Intent,
    p1: UserHandle,
    p2: String?,
    p3: BroadcastReceiver?,
    p4: Handler?,
    p5: Int,
    p6: String?,
    p7: Bundle?
)
open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
sendStickyOrderedBroadcast(
    p0: Intent,
    p1: BroadcastReceiver?,
    p2: Handler?,
    p3: Int,
    p4: String?,
    p5: Bundle?
)

This function is deprecated. Deprecated in Java

open Unit
sendStickyOrderedBroadcastAsUser(
    p0: Intent,
    p1: UserHandle,
    p2: BroadcastReceiver?,
    p3: Handler?,
    p4: Int,
    p5: String?,
    p6: Bundle?
)

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open ComponentName?
open Boolean
open ComponentName?
open Boolean
open Unit
open Unit
open Unit
open Unit
From android.view.Window.Callback

Public constructors

ComponentActivity

Added in 1.0.0
ComponentActivity()

ComponentActivity

Added in 1.0.0
@ContentView
ComponentActivity(contentLayoutId: @LayoutRes 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 functions

addContentView

open fun addContentView(view: View?, params: ViewGroup.LayoutParams?): Unit

addMenuProvider

Added in 1.4.0
open fun addMenuProvider(provider: MenuProvider): Unit

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

Parameters
provider: MenuProvider

the MenuProvider to be added

addMenuProvider

Added in 1.4.0
open fun addMenuProvider(provider: MenuProvider, owner: LifecycleOwner): Unit

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

Parameters
provider: MenuProvider

the MenuProvider to be added

owner: LifecycleOwner

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

addMenuProvider

Added in 1.4.0
open fun addMenuProvider(
    provider: MenuProvider,
    owner: LifecycleOwner,
    state: Lifecycle.State
): Unit

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
provider: MenuProvider

the MenuProvider to be added

owner: LifecycleOwner

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

state: Lifecycle.State

the Lifecycle.State to check for automated addition/removal

addOnConfigurationChangedListener

Added in 1.5.0
final fun addOnConfigurationChangedListener(listener: Consumer<Configuration>): Unit

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

Parameters
listener: Consumer<Configuration>

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

addOnContextAvailableListener

Added in 1.10.0-beta01
final fun addOnContextAvailableListener(listener: OnContextAvailableListener): Unit

{@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
final fun addOnMultiWindowModeChangedListener(
    listener: Consumer<MultiWindowModeChangedInfo>
): Unit

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

Parameters
listener: Consumer<MultiWindowModeChangedInfo>

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

addOnNewIntentListener

Added in 1.5.0
final fun addOnNewIntentListener(listener: Consumer<Intent>): Unit

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

Parameters
listener: Consumer<Intent>

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

addOnPictureInPictureModeChangedListener

Added in 1.5.0
final fun addOnPictureInPictureModeChangedListener(
    listener: Consumer<PictureInPictureModeChangedInfo>
): Unit

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

Parameters
listener: Consumer<PictureInPictureModeChangedInfo>

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

addOnTrimMemoryListener

Added in 1.5.0
final fun addOnTrimMemoryListener(listener: Consumer<Int>): Unit

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

Parameters
listener: Consumer<Int>

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

addOnUserLeaveHintListener

Added in 1.9.0
final fun addOnUserLeaveHintListener(listener: Runnable): Unit

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

Parameters
listener: Runnable

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

initializeViewTreeOwners

Added in 1.8.0
@CallSuper
open fun initializeViewTreeOwners(): Unit

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
open fun invalidateMenu(): Unit

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
open fun onBackPressed(): Unit

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
open fun onConfigurationChanged(newConfig: Configuration): Unit

{@inheritDoc}

Dispatches this call to all listeners added via addOnConfigurationChangedListener.

onCreatePanelMenu

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

onMenuItemSelected

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

onMultiWindowModeChanged

Added in 1.5.0
@CallSuper
open fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean): Unit

{@inheritDoc}

Dispatches this call to all listeners added via addOnMultiWindowModeChangedListener.

onMultiWindowModeChanged

@RequiresApi(api = 26)
@CallSuper
open fun onMultiWindowModeChanged(
    isInMultiWindowMode: Boolean,
    newConfig: Configuration
): Unit

{@inheritDoc}

Dispatches this call to all listeners added via addOnMultiWindowModeChangedListener.

onPanelClosed

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

onPictureInPictureModeChanged

Added in 1.5.0
@CallSuper
open fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean): Unit

{@inheritDoc}

Dispatches this call to all listeners added via addOnPictureInPictureModeChangedListener.

onPictureInPictureModeChanged

@RequiresApi(api = 26)
@CallSuper
open fun onPictureInPictureModeChanged(
    isInPictureInPictureMode: Boolean,
    newConfig: Configuration
): Unit

{@inheritDoc}

Dispatches this call to all listeners added via addOnPictureInPictureModeChangedListener.

onPreparePanel

open fun onPreparePanel(featureId: Int, view: View?, menu: Menu): Boolean

onRequestPermissionsResult

Added in 1.2.0
Deprecated in 1.2.0
@CallSuper
open fun onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<String>,
    grantResults: IntArray
): Unit

{@inheritDoc}

onRetainCustomNonConfigurationInstance

Added in 1.0.0
Deprecated in 1.0.0
open fun onRetainCustomNonConfigurationInstance(): Any?

Use this instead of onRetainNonConfigurationInstance. Retrieve later with lastCustomNonConfigurationInstance.

onRetainNonConfigurationInstance

Added in 1.0.0
final fun onRetainNonConfigurationInstance(): Any?

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
open fun onTrimMemory(level: Int): Unit

{@inheritDoc}

Dispatches this call to all listeners added via addOnTrimMemoryListener.

peekAvailableContext

Added in 1.10.0-beta01
open fun peekAvailableContext(): Context?

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

Added in 1.10.0-beta01
final fun <I : Any?, O : Any?> registerForActivityResult(
    contract: ActivityResultContract<I, O>,
    callback: ActivityResultCallback<O>
): ActivityResultLauncher<I>

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 : Any?>

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

<O : Any?>

the type of output returned as an activity result

contract: ActivityResultContract<I, O>

the contract, specifying conversions to/from Intents

callback: ActivityResultCallback<O>

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

Returns
ActivityResultLauncher<I>

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

registerForActivityResult

Added in 1.10.0-beta01
final fun <I : Any?, O : Any?> registerForActivityResult(
    contract: ActivityResultContract<I, O>,
    registry: ActivityResultRegistry,
    callback: ActivityResultCallback<O>
): ActivityResultLauncher<I>

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 : Any?>

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

<O : Any?>

the type of output returned as an activity result

contract: ActivityResultContract<I, O>

the contract, specifying conversions to/from Intents

registry: ActivityResultRegistry

the registry where to hold the record.

callback: ActivityResultCallback<O>

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

Returns
ActivityResultLauncher<I>

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

removeMenuProvider

Added in 1.4.0
open fun removeMenuProvider(provider: MenuProvider): Unit

Removes the given MenuProvider from this MenuHost.

Parameters
provider: MenuProvider

the MenuProvider to be removed

removeOnConfigurationChangedListener

Added in 1.5.0
final fun removeOnConfigurationChangedListener(listener: Consumer<Configuration>): Unit

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

Parameters
listener: Consumer<Configuration>

The listener previously added with addOnConfigurationChangedListener that should be removed.

removeOnContextAvailableListener

Added in 1.10.0-beta01
final fun removeOnContextAvailableListener(listener: OnContextAvailableListener): Unit

Remove a OnContextAvailableListener previously added via addOnContextAvailableListener.

Parameters
listener: OnContextAvailableListener

The listener that should be removed.

removeOnMultiWindowModeChangedListener

Added in 1.5.0
final fun removeOnMultiWindowModeChangedListener(
    listener: Consumer<MultiWindowModeChangedInfo>
): Unit

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

Parameters
listener: Consumer<MultiWindowModeChangedInfo>

The listener previously added with addOnMultiWindowModeChangedListener that should be removed.

removeOnNewIntentListener

Added in 1.5.0
final fun removeOnNewIntentListener(listener: Consumer<Intent>): Unit

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

Parameters
listener: Consumer<Intent>

The listener previously added with addOnNewIntentListener that should be removed.

removeOnPictureInPictureModeChangedListener

Added in 1.5.0
final fun removeOnPictureInPictureModeChangedListener(
    listener: Consumer<PictureInPictureModeChangedInfo>
): Unit

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

Parameters
listener: Consumer<PictureInPictureModeChangedInfo>

The listener previously added with addOnPictureInPictureModeChangedListener that should be removed.

removeOnTrimMemoryListener

Added in 1.5.0
final fun removeOnTrimMemoryListener(listener: Consumer<Int>): Unit

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

Parameters
listener: Consumer<Int>

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

removeOnUserLeaveHintListener

Added in 1.9.0
final fun removeOnUserLeaveHintListener(listener: Runnable): Unit

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

Parameters
listener: Runnable

The listener previously added with addOnUserLeaveHintListener that should be removed.

reportFullyDrawn

open fun reportFullyDrawn(): Unit

setContentView

open fun setContentView(layoutResID: @LayoutRes Int): Unit

setContentView

open fun setContentView(view: View?): Unit

setContentView

open fun setContentView(view: View?, params: ViewGroup.LayoutParams?): Unit

startActivityForResult

Added in 1.2.0
Deprecated in 1.2.0
open fun startActivityForResult(intent: Intent, requestCode: Int): Unit

{@inheritDoc}

startActivityForResult

Added in 1.2.0
Deprecated in 1.2.0
open fun startActivityForResult(intent: Intent, requestCode: Int, options: Bundle?): Unit

{@inheritDoc}

startIntentSenderForResult

Added in 1.2.0
Deprecated in 1.2.0
open fun startIntentSenderForResult(
    intent: IntentSender,
    requestCode: Int,
    fillInIntent: Intent?,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int
): Unit

{@inheritDoc}

startIntentSenderForResult

Added in 1.2.0
Deprecated in 1.2.0
open fun startIntentSenderForResult(
    intent: IntentSender,
    requestCode: Int,
    fillInIntent: Intent?,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int,
    options: Bundle?
): Unit

{@inheritDoc}

Protected functions

onActivityResult

Added in 1.2.0
Deprecated in 1.2.0
@CallSuper
protected open fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Unit

{@inheritDoc}

onCreate

protected open fun onCreate(savedInstanceState: Bundle?): Unit

{@inheritDoc}

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

onNewIntent

@CallSuper
protected open fun onNewIntent(intent: Intent): Unit

{@inheritDoc}

Dispatches this call to all listeners added via addOnNewIntentListener.

onSaveInstanceState

@CallSuper
protected open fun onSaveInstanceState(outState: Bundle): Unit

onUserLeaveHint

@CallSuper
protected open fun onUserLeaveHint(): Unit

{@inheritDoc}

Dispatches this call to all listeners added via addOnUserLeaveHintListener.

Public properties

activityResultRegistry

Added in 1.10.0-beta01
final val activityResultRegistryActivityResultRegistry

Get the ActivityResultRegistry associated with this activity.

defaultViewModelCreationExtras

open val defaultViewModelCreationExtrasCreationExtras

defaultViewModelProviderFactory

Added in 1.1.0
open val defaultViewModelProviderFactoryViewModelProvider.Factory

fullyDrawnReporter

Added in 1.10.0-beta01
open val fullyDrawnReporterFullyDrawnReporter

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

lastCustomNonConfigurationInstance

Added in 1.0.0
Deprecated in 1.0.0
open val lastCustomNonConfigurationInstanceAny?

lifecycle

Added in 1.0.0
open val lifecycleLifecycle

{@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.

onBackPressedDispatcher

Added in 1.10.0-beta01
final val onBackPressedDispatcherOnBackPressedDispatcher

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

Returns
OnBackPressedDispatcher

The OnBackPressedDispatcher associated with this ComponentActivity.

savedStateRegistry

Added in 1.0.0
final val savedStateRegistrySavedStateRegistry

viewModelStore

Added in 1.0.0
open val viewModelStoreViewModelStore

Extension functions

setSubspaceContent

fun ComponentActivity.setSubspaceContent(
    session: Session? = null,
    enableXrForTesting: Boolean = false,
    content: @Composable @SubspaceComposable () -> Unit
): Unit

Composes the provided composable content into this activity's subspace.

This method only takes effect in Android XR. Calling it will cause the activity to register itself as a subspace, allowing it to control its own panel (i.e. move and resize within its subspace 3D bounds) and show additional spatial content around it.

Parameters
session: Session? = null

A custom session to be provided for testing purposes. If null, a suitable session for production use will be created.

enableXrForTesting: Boolean = false

When set, this method will assume it is running on Android XR even if it is not. Should only be used for testing, it will cause crashes on non-Android XR devices.

content: @Composable @SubspaceComposable () -> Unit

A @Composable function declaring the spatial UI content.

@MainThread
inline fun <VM : ViewModel> ComponentActivity.viewModels(
    noinline extrasProducer: (() -> CreationExtras)? = null,
    noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null
): Lazy<VM>

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.

fun ComponentActivity.setContent(
    parent: CompositionContext? = null,
    content: @Composable () -> Unit
): Unit

Composes the given composable into the given activity. The content will become the root view of the given activity.

This is roughly equivalent to calling ComponentActivity.setContentView with a ComposeView i.e.:

setContentView(
ComposeView(this).apply {
setContent {
MyComposableContent()
}
}
)
Parameters
parent: CompositionContext? = null

The parent composition reference to coordinate scheduling of composition updates

content: @Composable () -> Unit

A @Composable function declaring the UI contents

enableEdgeToEdge

fun ComponentActivity.enableEdgeToEdge(
    statusBarStyle: SystemBarStyle = SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT),
    navigationBarStyle: SystemBarStyle = SystemBarStyle.auto(DefaultLightScrim, DefaultDarkScrim)
): Unit

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
statusBarStyle: SystemBarStyle = SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT)

The SystemBarStyle for the status bar.

navigationBarStyle: SystemBarStyle = SystemBarStyle.auto(DefaultLightScrim, DefaultDarkScrim)

The SystemBarStyle for the navigation bar.