ComponentActivity

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

Known direct subclasses
FragmentActivity

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

SdkActivity

Activity to start for SDKs running locally.

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

Default constructor for ComponentActivity.

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

Public functions

Unit
Unit

Adds the given MenuProvider to this MenuHost.

Unit

Adds the given MenuProvider to this MenuHost.

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.

Unit

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

Unit

Add a new OnContextAvailableListener for receiving a callback for when this class is associated with a android.content.Context.

Unit

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

Unit

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

Unit

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

Unit

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

Boolean
Boolean
ActivityResultRegistry

Get the ActivityResultRegistry associated with this activity.

CreationExtras

Returns the default CreationExtras that should be passed into ViewModelProvider.Factory.create when no overriding CreationExtras were passed to the ViewModelProvider constructors.

ViewModelProvider.Factory

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

FullyDrawnReporter

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

Any?

This function is deprecated.

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

Lifecycle

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

OnBackPressedDispatcher

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

SavedStateRegistry

The SavedStateRegistry owned by this SavedStateRegistryOwner

ViewModelStore

Returns the ViewModelStore associated with this activity

Unit

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

Unit

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

Unit

This function is deprecated.

This method has been deprecated in favor of using the OnBackPressedDispatcher via getOnBackPressedDispatcher.

Unit

Dispatches this call to all listeners added via addOnConfigurationChangedListener.

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

Dispatches this call to all listeners added via addOnMultiWindowModeChangedListener.

Unit
@RequiresApi(api = Build.VERSION_CODES.O)
@CallSuper
onMultiWindowModeChanged(
    isInMultiWindowMode: Boolean,
    newConfig: Configuration
)

Dispatches this call to all listeners added via addOnMultiWindowModeChangedListener.

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

Dispatches this call to all listeners added via addOnPictureInPictureModeChangedListener.

Unit
@RequiresApi(api = Build.VERSION_CODES.O)
@CallSuper
onPictureInPictureModeChanged(
    isInPictureInPictureMode: Boolean,
    newConfig: Configuration
)

Dispatches this call to all listeners added via addOnPictureInPictureModeChangedListener.

Boolean
onPreparePanel(featureId: Int, view: View?, menu: Menu)
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 ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your activity.

Any?

This function is deprecated.

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

Any?

Retain all appropriate non-config state.

Unit

Dispatches this call to all listeners added via addOnTrimMemoryListener.

Context?

Get the Context if it is currently available.

ActivityResultLauncher<I!>
<I, O> registerForActivityResult(
    contract: ActivityResultContract<I!, O!>,
    callback: ActivityResultCallback<O!>
)

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

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

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

Unit

Removes the given MenuProvider from this MenuHost.

Unit

Remove a previously added listener.

Unit

Remove a OnContextAvailableListener previously added via addOnContextAvailableListener.

Unit

Remove a previously added listener.

Unit

Remove a previously added listener.

Unit

Remove a previously added listener.

Unit

Remove a previously added listener.

Unit
Unit
setContentView(layoutResID: @LayoutRes Int)
Unit
Unit
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 ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your activity.

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 ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your activity.

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 ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your activity.

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 ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your activity.

Protected functions

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 ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your activity.

Unit
onCreate(savedInstanceState: Bundle?)

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

Unit

Dispatches this call to all listeners added via addOnNewIntentListener.

Unit
Boolean

Checks if the internal state should be dump, as some special args are handled by Activity itself.

Extension functions

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 Constants

From android.app.Activity
From android.content.ComponentCallbacks2
From android.content.Context
const String!
ACCESSIBILITY_SERVICE = "accessibility"
const String!
ACCOUNT_SERVICE = "account"
const String!
ACTIVITY_SERVICE = "activity"
const String!
ALARM_SERVICE = "alarm"
const String!
APPWIDGET_SERVICE = "appwidget"
const String!
APP_OPS_SERVICE = "appops"
const String!
APP_SEARCH_SERVICE = "app_search"
const String!
AUDIO_SERVICE = "audio"
const String!
BATTERY_SERVICE = "batterymanager"
const Int
const Int
const Int
const Int
const Int
const Int
const Int
BIND_EXTERNAL_SERVICE = -2147483648
const Long
BIND_EXTERNAL_SERVICE_LONG = 4611686018427387904
const Int
const Int
const Int
const Int
const Int
const Int
const String!
BIOMETRIC_SERVICE = "biometric"
const String!
BLOB_STORE_SERVICE = "blob_store"
const String!
BLUETOOTH_SERVICE = "bluetooth"
const String!
BUGREPORT_SERVICE = "bugreport"
const String!
CAMERA_SERVICE = "camera"
const String!
CAPTIONING_SERVICE = "captioning"
const String!
CARRIER_CONFIG_SERVICE = "carrier_config"
const String!
CLIPBOARD_SERVICE = "clipboard"
const String!
COMPANION_DEVICE_SERVICE = "companiondevice"
const String!
CONNECTIVITY_DIAGNOSTICS_SERVICE = "connectivity_diagnostics"
const String!
CONNECTIVITY_SERVICE = "connectivity"
const String!
CONSUMER_IR_SERVICE = "consumer_ir"
const Int
const Int
const Int
const String!
CREDENTIAL_SERVICE = "credential"
const String!
CROSS_PROFILE_APPS_SERVICE = "crossprofileapps"
const Int
const Int
const String!
DEVICE_LOCK_SERVICE = "device_lock"
const String!
DEVICE_POLICY_SERVICE = "device_policy"
const String!
DISPLAY_HASH_SERVICE = "display_hash"
const String!
DISPLAY_SERVICE = "display"
const String!
DOMAIN_VERIFICATION_SERVICE = "domain_verification"
const String!
DOWNLOAD_SERVICE = "download"
const String!
DROPBOX_SERVICE = "dropbox"
const String!
EUICC_SERVICE = "euicc"
const String!
FILE_INTEGRITY_SERVICE = "file_integrity"
const String!
FINGERPRINT_SERVICE = "fingerprint"
const String!
GAME_SERVICE = "game"
const String!
GRAMMATICAL_INFLECTION_SERVICE = "grammatical_inflection"
const String!
HARDWARE_PROPERTIES_SERVICE = "hardware_properties"
const String!
HEALTHCONNECT_SERVICE = "healthconnect"
const String!
INPUT_METHOD_SERVICE = "input_method"
const String!
INPUT_SERVICE = "input"
const String!
IPSEC_SERVICE = "ipsec"
const String!
JOB_SCHEDULER_SERVICE = "jobscheduler"
const String!
KEYGUARD_SERVICE = "keyguard"
const String!
LAUNCHER_APPS_SERVICE = "launcherapps"
const String!
LAYOUT_INFLATER_SERVICE = "layout_inflater"
const String!
LOCALE_SERVICE = "locale"
const String!
LOCATION_SERVICE = "location"
const String!
MEDIA_COMMUNICATION_SERVICE = "media_communication"
const String!
MEDIA_METRICS_SERVICE = "media_metrics"
const String!
MEDIA_PROJECTION_SERVICE = "media_projection"
const String!
MEDIA_ROUTER_SERVICE = "media_router"
const String!
MEDIA_SESSION_SERVICE = "media_session"
const String!
MIDI_SERVICE = "midi"
const Int
MODE_APPEND = 32768
const Int
const Int

This property is deprecated.

const Int
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const String!
const String!
NFC_SERVICE = "nfc"
const String!
NOTIFICATION_SERVICE = "notification"
const String!
NSD_SERVICE = "servicediscovery"
const String!
OVERLAY_SERVICE = "overlay"
const String!
PEOPLE_SERVICE = "people"
const String!
PERFORMANCE_HINT_SERVICE = "performance_hint"
const String!
POWER_SERVICE = "power"
const String!
PRINT_SERVICE = "print"
const Int
const Int
const Int
const String!
RESTRICTIONS_SERVICE = "restrictions"
const String!
ROLE_SERVICE = "role"
const String!
SEARCH_SERVICE = "search"
const String!
SENSOR_SERVICE = "sensor"
const String!
SHORTCUT_SERVICE = "shortcut"
const String!
STATUS_BAR_SERVICE = "statusbar"
const String!
STORAGE_SERVICE = "storage"
const String!
STORAGE_STATS_SERVICE = "storagestats"
const String!
SYSTEM_HEALTH_SERVICE = "systemhealth"
const String!
TELECOM_SERVICE = "telecom"
const String!
TELEPHONY_IMS_SERVICE = "telephony_ims"
const String!
const String!
TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service"
const String!
TEXT_CLASSIFICATION_SERVICE = "textclassification"
const String!
const String!
TV_INPUT_SERVICE = "tv_input"
const String!
TV_INTERACTIVE_APP_SERVICE = "tv_interactive_app"
const String!
UI_MODE_SERVICE = "uimode"
const String!
USAGE_STATS_SERVICE = "usagestats"
const String!
USB_SERVICE = "usb"
const String!
USER_SERVICE = "user"
const String!
VIBRATOR_MANAGER_SERVICE = "vibrator_manager"
const String!
VIBRATOR_SERVICE = "vibrator"

This property is deprecated.

const String!
VIRTUAL_DEVICE_SERVICE = "virtualdevice"
const String!
VPN_MANAGEMENT_SERVICE = "vpn_management"
const String!
WALLPAPER_SERVICE = "wallpaper"
const String!
WIFI_AWARE_SERVICE = "wifiaware"
const String!
WIFI_P2P_SERVICE = "wifip2p"
const String!
const String!
WIFI_SERVICE = "wifi"
const String!
WINDOW_SERVICE = "window"

Inherited functions

From android.app.Activity
Unit
Unit
Unit
Unit
PendingIntent!
createPendingResult(requestCode: Int, data: Intent!, flags: Int)
Unit

This function is deprecated.

Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Unit
dump(
    prefix: String!,
    fd: FileDescriptor!,
    writer: PrintWriter!,
    args: Array<String!>!
)
Unit

This function is deprecated.

Boolean
T!
<T : View?> findViewById(id: Int)
Unit
Unit
finishActivity(requestCode: Int)
Unit
finishActivityFromChild(child: Activity!, requestCode: Int)

This function is deprecated.

Unit
Unit
Unit
Unit

This function is deprecated.

ActionBar!
Application!
ComponentName!
String!
Int
ComponentName!
Scene!
TransitionManager!
View!
FragmentManager!

This function is deprecated.

Intent!
Any!
String!
Int
LayoutInflater!
LoaderManager!

This function is deprecated.

String!
Int
MediaController!
MenuInflater!
OnBackInvokedDispatcher!
Activity!
Intent!
SharedPreferences!
Uri!
Int
SearchEvent!
SplashScreen!
Any!
Int
CharSequence!
Int
VoiceInteractor!
Int
Window!
WindowManager!
Boolean
Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Cursor!
managedQuery(
    uri: Uri!,
    projection: Array<String!>!,
    selection: String!,
    selectionArgs: Array<String!>!,
    sortOrder: String!
)

This function is deprecated.

Boolean
Boolean
navigateUpTo(upIntent: Intent!)
Boolean
navigateUpToFromChild(child: Activity!, upIntent: Intent!)

This function is deprecated.

Unit
Unit
Unit
onActivityReenter(resultCode: Int, data: Intent!)
Unit
onApplyThemeResource(theme: Resources.Theme!, resid: Int, first: Boolean)
Unit

This function is deprecated.

Unit
Unit
onChildTitleChanged(childActivity: Activity!, title: CharSequence!)
Unit
Boolean
Unit
Unit
onCreate(savedInstanceState: Bundle!)
Unit
onCreateContextMenu(
    menu: ContextMenu!,
    v: View!,
    menuInfo: ContextMenu.ContextMenuInfo!
)
CharSequence!
Dialog!

This function is deprecated.

Unit
Boolean
View!
onCreatePanelView(featureId: Int)
Boolean
onCreateThumbnail(outBitmap: Bitmap!, canvas: Canvas!)

This function is deprecated.

View!
onCreateView(name: String!, context: Context!, attrs: AttributeSet!)
Unit
Unit
Unit
Boolean
Unit
onGetDirectActions(
    cancellationSignal: CancellationSignal!,
    callback: Consumer<(Mutable)List<DirectAction!>!>!
)
Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)
Boolean
onKeyLongPress(keyCode: Int, event: KeyEvent!)
Boolean
onKeyMultiple(keyCode: Int, repeatCount: Int, event: KeyEvent!)
Boolean
onKeyShortcut(keyCode: Int, event: KeyEvent!)
Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)
Unit
Unit
Unit
Boolean
onMenuOpened(featureId: Int, menu: Menu!)
Boolean
Boolean

This function is deprecated.

Boolean
Unit
Unit
Unit
onPerformDirectAction(
    actionId: String!,
    arguments: Bundle!,
    cancellationSignal: CancellationSignal!,
    resultListener: Consumer<Bundle!>!
)
Boolean
Unit
Unit
onPostCreate(savedInstanceState: Bundle!)
Unit
Unit
onPrepareDialog(id: Int, dialog: Dialog!)

This function is deprecated.

Unit
Boolean
Unit
Unit
Unit
onProvideKeyboardShortcuts(
    data: (Mutable)List<KeyboardShortcutGroup!>!,
    menu: Menu!,
    deviceId: Int
)
Uri!
Unit
Unit
onRestoreInstanceState(savedInstanceState: Bundle!)
Unit
Unit
Boolean
Unit
Unit

This function is deprecated.

Unit
Unit
onTitleChanged(title: CharSequence!, color: Int)
Unit
onTopResumedActivityChanged(isTopResumedActivity: Boolean)
Boolean
Boolean
Unit
Unit
Unit

This function is deprecated.

Unit
Unit
ActionMode!
Unit
Unit
Unit
overrideActivityTransition(
    overrideType: Int,
    enterAnim: Int,
    exitAnim: Int
)
Unit
overridePendingTransition(enterAnim: Int, exitAnim: Int)

This function is deprecated.

Unit
Unit
Unit
Unit
Unit
Unit
Boolean
Unit

This function is deprecated.

DragAndDropPermissions!
Unit
requestFullscreenMode(
    request: Int,
    approvalCallback: OutcomeReceiver<Void!, Throwable!>!
)
Unit
requestPermissions(permissions: Array<String!>!, requestCode: Int)
Unit
Boolean

This function is deprecated.

Boolean
T!
<T : View?> requireViewById(id: Int)
Unit
Unit
setActionBar(toolbar: Toolbar!)
Unit
Unit
Unit
Unit
Unit
setFeatureDrawable(featureId: Int, drawable: Drawable!)
Unit
setFeatureDrawableAlpha(featureId: Int, alpha: Int)
Unit
setFeatureDrawableResource(featureId: Int, resId: Int)
Unit
setFeatureDrawableUri(featureId: Int, uri: Uri!)
Unit
Unit
Unit
setInheritShowWhenLocked(inheritShowWhenLocked: Boolean)
Unit
setIntent(newIntent: Intent!)
Unit
setLocusContext(locusId: LocusId!, bundle: Bundle!)
Unit
Unit
Unit
setProgress(progress: Int)

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
Unit
setRequestedOrientation(requestedOrientation: Int)
Unit
setResult(resultCode: Int)
Unit
setSecondaryProgress(secondaryProgress: Int)

This function is deprecated.

Unit
setShouldDockBigOverlays(shouldDockBigOverlays: Boolean)
Unit
setShowWhenLocked(showWhenLocked: Boolean)
Unit
Unit
setTheme(resid: Int)
Unit
Unit
setTitleColor(textColor: Int)

This function is deprecated.

Boolean
setTranslucent(translucent: Boolean)
Unit
setTurnScreenOn(turnScreenOn: Boolean)
Unit
setVisible(visible: Boolean)
Unit
Unit
setVrModeEnabled(enabled: Boolean, requestedComponent: ComponentName!)
Boolean
Boolean
Boolean
shouldUpRecreateTask(targetIntent: Intent!)
Boolean
Unit

This function is deprecated.

Boolean
showDialog(id: Int, args: Bundle!)

This function is deprecated.

Unit
ActionMode!
Unit
Unit
Unit
startActivityFromChild(child: Activity!, intent: Intent!, requestCode: Int)

This function is deprecated.

Unit
startActivityFromFragment(
    fragment: Fragment!,
    intent: Intent!,
    requestCode: Int
)

This function is deprecated.

Boolean
startActivityIfNeeded(intent: Intent!, requestCode: Int)
Unit
startIntentSender(
    intent: IntentSender!,
    fillInIntent: Intent!,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int
)
Unit
startIntentSenderFromChild(
    child: Activity!,
    intent: IntentSender!,
    requestCode: Int,
    fillInIntent: Intent!,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int
)

This function is deprecated.

Unit
Unit
Unit

This function is deprecated.

Boolean
Unit
Unit
startSearch(
    initialQuery: String!,
    selectInitialQuery: Boolean,
    appSearchData: Bundle!,
    globalSearch: Boolean
)
Unit
Unit
Unit

This function is deprecated.

Unit
Unit
triggerSearch(query: String!, appSearchData: Bundle!)
Unit
Unit
Unit
Unit
From android.content.Context
From android.view.ContextThemeWrapper
From android.content.ContextWrapper
Boolean
bindIsolatedService(
    service: Intent!,
    flags: Int,
    instanceName: String!,
    executor: Executor!,
    conn: ServiceConnection!
)
Boolean
bindService(service: Intent!, conn: ServiceConnection!, flags: Int)
Boolean
bindServiceAsUser(
    service: Intent!,
    conn: ServiceConnection!,
    flags: Int,
    user: UserHandle!
)
Int
Int
IntArray<Int>!
checkCallingOrSelfUriPermissions(
    uris: (Mutable)List<Uri!>!,
    modeFlags: Int
)
Int
Int
checkCallingUriPermission(uri: Uri!, modeFlags: Int)
IntArray<Int>!
checkCallingUriPermissions(uris: (Mutable)List<Uri!>!, modeFlags: Int)
Int
checkPermission(permission: String!, pid: Int, uid: Int)
Int
Int
checkUriPermission(uri: Uri!, pid: Int, uid: Int, modeFlags: Int)
IntArray<Int>!
checkUriPermissions(
    uris: (Mutable)List<Uri!>!,
    pid: Int,
    uid: Int,
    modeFlags: Int
)
Unit

This function is deprecated.

Context!
createAttributionContext(attributionTag: String!)
Context!
createConfigurationContext(overrideConfiguration: Configuration!)
Context!
createContext(contextParams: ContextParams!)
Context!
Context!
Context!
Context!
Context!
createPackageContext(packageName: String!, flags: Int)
Context!
createWindowContext(type: Int, options: Bundle!)
Array<String!>!
Boolean
Boolean
Boolean
Unit
enforceCallingOrSelfPermission(permission: String!, message: String!)
Unit
enforceCallingOrSelfUriPermission(
    uri: Uri!,
    modeFlags: Int,
    message: String!
)
Unit
enforceCallingPermission(permission: String!, message: String!)
Unit
enforceCallingUriPermission(uri: Uri!, modeFlags: Int, message: String!)
Unit
enforcePermission(permission: String!, pid: Int, uid: Int, message: String!)
Unit
enforceUriPermission(
    uri: Uri!,
    pid: Int,
    uid: Int,
    modeFlags: Int,
    message: String!
)
Array<String!>!
Context!
ApplicationInfo!
AttributionSource!
String!
Context!
File!
ClassLoader!
File!
ContentResolver!
File!
File!
Int
File!
getDir(name: String!, mode: Int)
Display!
File!
Array<File!>!
File!
Array<File!>!
Array<File!>!

This function is deprecated.

File!
File!
Executor!
Looper!
File!
File!
Array<File!>!
String!
String!
PackageManager!
String!
String!
ContextParams!
SharedPreferences!
getSharedPreferences(name: String!, mode: Int)
String!
getSystemServiceName(serviceClass: Class<Any!>!)
Drawable!

This function is deprecated.

Int

This function is deprecated.

Int

This function is deprecated.

Unit
grantUriPermission(toPackage: String!, uri: Uri!, modeFlags: Int)
Boolean
Boolean
Boolean
Boolean
moveDatabaseFrom(sourceContext: Context!, name: String!)
Boolean
moveSharedPreferencesFrom(sourceContext: Context!, name: String!)
FileInputStream!
FileOutputStream!
openFileOutput(name: String!, mode: Int)
SQLiteDatabase!
openOrCreateDatabase(
    name: String!,
    mode: Int,
    factory: SQLiteDatabase.CursorFactory!
)
Drawable!

This function is deprecated.

Unit
Intent!
Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
Unit
revokeUriPermission(uri: Uri!, modeFlags: Int)
Unit
Unit
Unit
sendOrderedBroadcast(intent: Intent!, receiverPermission: String!)
Unit
sendOrderedBroadcastAsUser(
    intent: Intent!,
    user: UserHandle!,
    receiverPermission: String!,
    resultReceiver: BroadcastReceiver!,
    scheduler: Handler!,
    initialCode: Int,
    initialData: String!,
    initialExtras: Bundle!
)
Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
sendStickyOrderedBroadcast(
    intent: Intent!,
    resultReceiver: BroadcastReceiver!,
    scheduler: Handler!,
    initialCode: Int,
    initialData: String!,
    initialExtras: Bundle!
)

This function is deprecated.

Unit
sendStickyOrderedBroadcastAsUser(
    intent: Intent!,
    user: UserHandle!,
    resultReceiver: BroadcastReceiver!,
    scheduler: Handler!,
    initialCode: Int,
    initialData: String!,
    initialExtras: Bundle!
)

This function is deprecated.

Unit
setWallpaper(bitmap: Bitmap!)

This function is deprecated.

ComponentName!
Boolean
startInstrumentation(
    className: ComponentName!,
    profileFile: String!,
    arguments: Bundle!
)
ComponentName!
startService(service: Intent!)
Boolean
Unit
Unit
Unit
Unit
updateServiceGroup(conn: ServiceConnection!, group: Int, importance: Int)
From android.view.Window.Callback

Public constructors

ComponentActivity

Added in 1.0.0
ComponentActivity()

Default constructor for ComponentActivity. All Activities must have a default constructor for API 27 and lower devices or when using the default android.app.AppComponentFactory.

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

Added in 1.8.0-alpha06
fun addContentView(view: View!, params: ViewGroup.LayoutParams!): Unit

addMenuProvider

Added in 1.4.0
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
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
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
fun addOnConfigurationChangedListener(listener: Consumer<Configuration!>): Unit

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

Parameters
listener: Consumer<Configuration!>

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

addOnContextAvailableListener

Added in 1.8.0-alpha06
fun addOnContextAvailableListener(listener: OnContextAvailableListener): Unit

Add a new OnContextAvailableListener for receiving a callback for when this class is associated with a android.content.Context.

Listeners are triggered in the order they are added when added before the Context is available. Listeners added after the context has been made available will have the Context synchronously delivered to them as part of this call.

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 onCreate with the exception of restoring the state of the SavedStateRegistry for use in your listener.

addOnMultiWindowModeChangedListener

Added in 1.5.0
fun addOnMultiWindowModeChangedListener(
    listener: Consumer<MultiWindowModeChangedInfo!>
): Unit

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

Parameters
listener: Consumer<MultiWindowModeChangedInfo!>

The listener that should be called whenever onMultiWindowModeChanged was called.

addOnNewIntentListener

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

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

Parameters
listener: Consumer<Intent!>

The listener that should be called whenever onNewIntent was called.

addOnPictureInPictureModeChangedListener

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

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

Parameters
listener: Consumer<PictureInPictureModeChangedInfo!>

The listener that should be called whenever onPictureInPictureModeChanged was called.

addOnTrimMemoryListener

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

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

Parameters
listener: Consumer<Int!>

The listener that should be called whenever onTrimMemory was called.

dispatchKeyEvent

Added in 1.8.0-alpha06
fun dispatchKeyEvent(event: KeyEvent!): Boolean

dispatchKeyShortcutEvent

Added in 1.8.0-alpha06
fun dispatchKeyShortcutEvent(event: KeyEvent!): Boolean

getActivityResultRegistry

Added in 1.8.0-alpha06
fun getActivityResultRegistry(): ActivityResultRegistry

Get the ActivityResultRegistry associated with this activity.

getDefaultViewModelCreationExtras

Added in 1.8.0-alpha06
@CallSuper
fun getDefaultViewModelCreationExtras(): CreationExtras

Returns the default CreationExtras that should be passed into ViewModelProvider.Factory.create when no overriding CreationExtras were passed to the ViewModelProvider constructors.

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
fun getDefaultViewModelProviderFactory(): ViewModelProvider.Factory

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

getFullyDrawnReporter

Added in 1.8.0-alpha06
fun getFullyDrawnReporter(): FullyDrawnReporter

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
fun getLastCustomNonConfigurationInstance(): Any?

Return the value previously returned from onRetainCustomNonConfigurationInstance.

getLifecycle

Added in 1.0.0
fun getLifecycle(): Lifecycle

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.

getOnBackPressedDispatcher

Added in 1.8.0-alpha06
fun getOnBackPressedDispatcher(): OnBackPressedDispatcher

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

Returns
OnBackPressedDispatcher

The OnBackPressedDispatcher associated with this ComponentActivity.

getSavedStateRegistry

Added in 1.0.0
fun getSavedStateRegistry(): SavedStateRegistry

The SavedStateRegistry owned by this SavedStateRegistryOwner

getViewModelStore

Added in 1.0.0
fun getViewModelStore(): ViewModelStore

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.

Returns
ViewModelStore

a ViewModelStore

Throws
java.lang.IllegalStateException

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

initializeViewTreeOwners

Added in 1.8.0-alpha06
@CallSuper
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
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
Deprecated in 1.8.0-alpha06
@MainThread
@CallSuper
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 onBackPressed is invoked.

onConfigurationChanged

Added in 1.8.0-alpha06
@CallSuper
fun onConfigurationChanged(newConfig: Configuration): Unit

Dispatches this call to all listeners added via addOnConfigurationChangedListener.

onCreatePanelMenu

Added in 1.8.0-alpha06
fun onCreatePanelMenu(featureId: Int, menu: Menu): Boolean

onMenuItemSelected

Added in 1.8.0-alpha06
fun onMenuItemSelected(featureId: Int, item: MenuItem): Boolean

onMultiWindowModeChanged

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

Dispatches this call to all listeners added via addOnMultiWindowModeChangedListener.

onMultiWindowModeChanged

Added in 1.8.0-alpha06
@RequiresApi(api = Build.VERSION_CODES.O)
@CallSuper
fun onMultiWindowModeChanged(
    isInMultiWindowMode: Boolean,
    newConfig: Configuration
): Unit

Dispatches this call to all listeners added via addOnMultiWindowModeChangedListener.

onPanelClosed

Added in 1.8.0-alpha06
fun onPanelClosed(featureId: Int, menu: Menu): Unit

onPictureInPictureModeChanged

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

Dispatches this call to all listeners added via addOnPictureInPictureModeChangedListener.

onPictureInPictureModeChanged

Added in 1.8.0-alpha06
@RequiresApi(api = Build.VERSION_CODES.O)
@CallSuper
fun onPictureInPictureModeChanged(
    isInPictureInPictureMode: Boolean,
    newConfig: Configuration
): Unit

Dispatches this call to all listeners added via addOnPictureInPictureModeChangedListener.

onPreparePanel

Added in 1.8.0-alpha06
fun onPreparePanel(featureId: Int, view: View?, menu: Menu): Boolean

onRequestPermissionsResult

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

onRetainCustomNonConfigurationInstance

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

Use this instead of onRetainNonConfigurationInstance. Retrieve later with getLastCustomNonConfigurationInstance.

onRetainNonConfigurationInstance

Added in 1.0.0
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

Added in 1.8.0-alpha06
@CallSuper
fun onTrimMemory(level: Int): Unit

Dispatches this call to all listeners added via addOnTrimMemoryListener.

peekAvailableContext

Added in 1.8.0-alpha06
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.8.0-alpha06
fun <I, O> 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>

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

<O>

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.8.0-alpha06
fun <I, O> 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>

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

<O>

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
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
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.8.0-alpha06
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
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
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
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
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.

reportFullyDrawn

Added in 1.8.0-alpha06
fun reportFullyDrawn(): Unit

setContentView

Added in 1.8.0-alpha06
fun setContentView(layoutResID: @LayoutRes Int): Unit

setContentView

Added in 1.8.0-alpha06
fun setContentView(view: View!): Unit

setContentView

Added in 1.8.0-alpha06
fun setContentView(view: View!, params: ViewGroup.LayoutParams!): Unit

startActivityForResult

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

startActivityForResult

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

startIntentSenderForResult

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

startIntentSenderForResult

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

Protected functions

onActivityResult

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

onCreate

Added in 1.8.0-alpha06
protected fun onCreate(savedInstanceState: Bundle?): Unit

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

onNewIntent

Added in 1.8.0-alpha06
@CallSuper
protected fun onNewIntent(intent: Intent!): Unit

Dispatches this call to all listeners added via addOnNewIntentListener.

onSaveInstanceState

Added in 1.8.0-alpha06
@CallSuper
protected fun onSaveInstanceState(outState: Bundle): Unit

shouldDumpInternalState

protected fun shouldDumpInternalState(args: Array<String!>?): Boolean

Checks if the internal state should be dump, as some special args are handled by Activity itself.

Subclasses implementing dump should typically start with:

@Override
public void dump(@NonNull String prefix, @Nullable FileDescriptor fd,
       @NonNull PrintWriter writer, @Nullable String[] args) {
   super.dump(prefix, fd, writer, args);

   if (!shouldDumpInternalState(args)) {
       return;
   }
   // dump internal starte
}

Extension functions

viewModels

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

setContent

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.