# ActivityCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/app/ActivityCompat.java+class:androidx.core.app.ActivityCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***

<br />

```
class ActivityCompat : ContextCompat
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.core.content.ContextCompat](https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat) ||
|   | ↳ | [androidx.core.app.ActivityCompat](https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat) |

*** ** * ** ***

Helper for accessing features in `https://developer.android.com/reference/android/app/Activity.html`.

## Summary

| ### Nested types |
|---|
| `interface https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat.OnRequestPermissionsResultCallback` This interface is the contract for receiving the results for permission requests. |
| `interface https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat.PermissionCompatDelegate` Customizable delegate that allows delegating permission compatibility methods to a custom implementation. |

| ### Protected constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#ActivityCompat()()` This class should not be instantiated, but the constructor must be visible for the class to be extended (as in support-v13). |

| ### Public functions |
|---|---|
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#finishAffinity(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` Finish this activity, and tries to finish all activities immediately below it in the current task that have the same affinity. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#finishAfterTransition(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` Reverses the Activity Scene entry Transition and triggers the calling Activity to reverse its exit Transition. |
| `java-static https://developer.android.com/reference/android/net/Uri.html?` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#getReferrer(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` Return information about who launched this activity. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `[invalidateOptionsMenu](https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#invalidateOptionsMenu(android.app.Activity))(activity: https://developer.android.com/reference/android/app/Activity.html!)` **This function is deprecated.** Use `https://developer.android.com/reference/android/app/Activity.html#invalidateOptionsMenu()` directly. <br /> |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#isLaunchedFromBubble(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` Indicates whether this activity is launched from a bubble. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#postponeEnterTransition(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#recreate(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` Cause the given Activity to be recreated with a new instance. |
| `java-static https://developer.android.com/reference/kotlin/androidx/core/view/DragAndDropPermissionsCompat?` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#requestDragAndDropPermissions(android.app.Activity,android.view.DragEvent)(activity: https://developer.android.com/reference/android/app/Activity.html, dragEvent: https://developer.android.com/reference/android/view/DragEvent.html)` Create `https://developer.android.com/reference/kotlin/androidx/core/view/DragAndDropPermissionsCompat` object bound to this activity and controlling the access permissions for content URIs associated with the `https://developer.android.com/reference/android/view/DragEvent.html`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#requestPermissions(android.app.Activity,java.lang.String[],int)( activity: https://developer.android.com/reference/android/app/Activity.html, permissions: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>, requestCode: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Requests permissions to be granted to this application. |
| `java-static T` | `<T : https://developer.android.com/reference/android/view/View.html?> https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#requireViewById(android.app.Activity,int)(activity: https://developer.android.com/reference/android/app/Activity.html, id: @https://developer.android.com/reference/kotlin/androidx/annotation/IdRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Finds a view that was identified by the `android:id` XML attribute that was processed in `https://developer.android.com/reference/android/app/Activity.html#onCreate(android.os.Bundle)`, or throws an IllegalArgumentException if the ID is invalid, or there is no matching view in the hierarchy. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#setEnterSharedElementCallback(android.app.Activity,androidx.core.app.SharedElementCallback)( activity: https://developer.android.com/reference/android/app/Activity.html, callback: https://developer.android.com/reference/kotlin/androidx/core/app/SharedElementCallback? )` When `https://developer.android.com/reference/android/app/ActivityOptions.html#makeSceneTransitionAnimation(android.app.Activity, android.view.View, java.lang.String)` was used to start an Activity, <var translate="no">callback</var> will be called to handle shared elements on the *launched* Activity. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#setExitSharedElementCallback(android.app.Activity,androidx.core.app.SharedElementCallback)( activity: https://developer.android.com/reference/android/app/Activity.html, callback: https://developer.android.com/reference/kotlin/androidx/core/app/SharedElementCallback? )` When `https://developer.android.com/reference/android/app/ActivityOptions.html#makeSceneTransitionAnimation(android.app.Activity, android.view.View, java.lang.String)` was used to start an Activity, <var translate="no">callback</var> will be called to handle shared elements on the *launching* Activity. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#setLocusContext(android.app.Activity,androidx.core.content.LocusIdCompat,android.os.Bundle)(activity: https://developer.android.com/reference/android/app/Activity.html, locusId: https://developer.android.com/reference/kotlin/androidx/core/content/LocusIdCompat?, bundle: https://developer.android.com/reference/android/os/Bundle.html?)` Sets the `https://developer.android.com/reference/kotlin/androidx/core/content/LocusIdCompat` for this activity. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#setPermissionCompatDelegate(androidx.core.app.ActivityCompat.PermissionCompatDelegate)( delegate: https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat.PermissionCompatDelegate? )` Sets the permission delegate for `ActivityCompat`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#shouldShowRequestPermissionRationale(android.app.Activity,java.lang.String)( activity: https://developer.android.com/reference/android/app/Activity.html, permission: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html )` Gets whether you should show UI with rationale before requesting a permission. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#startActivityForResult(android.app.Activity,android.content.Intent,int,android.os.Bundle)( activity: https://developer.android.com/reference/android/app/Activity.html, intent: https://developer.android.com/reference/android/content/Intent.html, requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, options: https://developer.android.com/reference/android/os/Bundle.html? )` Start new activity with options, if able, for which you would like a result when it finished. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#startIntentSenderForResult(android.app.Activity,android.content.IntentSender,int,android.content.Intent,int,int,int,android.os.Bundle)( activity: https://developer.android.com/reference/android/app/Activity.html, intent: https://developer.android.com/reference/android/content/IntentSender.html, requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, fillInIntent: https://developer.android.com/reference/android/content/Intent.html?, flagsMask: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, flagsValues: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, extraFlags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, options: https://developer.android.com/reference/android/os/Bundle.html? )` Start new IntentSender with options, if able, for which you would like a result when it finished. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#startPostponedEnterTransition(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` |

### Inherited Constants

From [androidx.core.content.ContextCompat](https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat) `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#RECEIVER_EXPORTED() = 2`

Flag for `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)`: The receiver can receive broadcasts from other Apps.
`const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#RECEIVER_NOT_EXPORTED() = 4`

Flag for `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)`: The receiver cannot receive broadcasts from other Apps.
`const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#RECEIVER_VISIBLE_TO_INSTANT_APPS() = 1`

Flag for `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)`: The receiver can receive broadcasts from Instant Apps.

### Inherited functions

From [androidx.core.content.ContextCompat](https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat) `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#checkSelfPermission(android.content.Context,java.lang.String)(context: https://developer.android.com/reference/android/content/Context.html, permission: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`

Determine whether *you* have been granted a particular permission.
`java-static https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#createAttributionContext(android.content.Context,java.lang.String)(context: https://developer.android.com/reference/android/content/Context.html, attributionTag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)`

Return a new Context object for the current Context but attribute to a different tag.
`java-static https://developer.android.com/reference/android/content/Context.html?` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#createDeviceProtectedStorageContext(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)`

Return a new Context object for the current Context but whose storage APIs are backed by device-protected storage.
`java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getAttributionTag(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)`

Attribution can be used in complex apps to logically separate parts of the app.
`java-static https://developer.android.com/reference/java/io/File.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getCodeCacheDir(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)`

Returns the absolute path to the application specific cache directory on the filesystem designed for storing cached code.
`java-static @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getColor(android.content.Context,int)(context: https://developer.android.com/reference/android/content/Context.html, id: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

Returns a color associated with a particular resource ID
`java-static https://developer.android.com/reference/android/content/res/ColorStateList.html?` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getColorStateList(android.content.Context,int)(context: https://developer.android.com/reference/android/content/Context.html, id: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

Returns a color state list associated with a particular resource ID.
`java-static https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getContextForLanguage(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)`

Gets the context which respects the per-app locales locale.
`java-static https://developer.android.com/reference/java/io/File.html?` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getDataDir(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)`

Returns the absolute path to the directory on the filesystem where all private files belonging to this app are stored.
`java-static https://developer.android.com/reference/android/view/Display.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getDisplayOrDefault(android.content.Context)(context: @https://developer.android.com/reference/kotlin/androidx/annotation/DisplayContext https://developer.android.com/reference/android/content/Context.html)`

Get the display this context is associated with or the `https://developer.android.com/reference/android/view/Display.html#DEFAULT_DISPLAY` as the fallback if the context is not associated with any `https://developer.android.com/reference/android/view/Display.html`.
`java-static https://developer.android.com/reference/android/graphics/drawable/Drawable.html?` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getDrawable(android.content.Context,int)(context: https://developer.android.com/reference/android/content/Context.html, id: @https://developer.android.com/reference/kotlin/androidx/annotation/DrawableRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

Returns a drawable object associated with a particular resource ID.
`java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/java/io/File.html!>` `@https://developer.android.com/reference/kotlin/androidx/annotation/ReplaceWith(expression = "context.getExternalCacheDirs()")
[getExternalCacheDirs](https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getExternalCacheDirs(android.content.Context))(context: https://developer.android.com/reference/android/content/Context.html)`

**This function is deprecated.**

Call `https://developer.android.com/reference/android/content/Context.html#getExternalCacheDirs()` directly.

<br />

`java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/java/io/File.html!>` `@https://developer.android.com/reference/kotlin/androidx/annotation/ReplaceWith(expression = "context.getExternalFilesDirs(type)")
[getExternalFilesDirs](https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getExternalFilesDirs(android.content.Context,java.lang.String))(context: https://developer.android.com/reference/android/content/Context.html, type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)`

**This function is deprecated.**

Call getExternalFilesDirs directly.

<br />

`java-static https://developer.android.com/reference/java/util/concurrent/Executor.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getMainExecutor(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)`

Return an `https://developer.android.com/reference/java/util/concurrent/Executor.html` that will run enqueued tasks on the main thread associated with this context.
`java-static https://developer.android.com/reference/java/io/File.html?` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getNoBackupFilesDir(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)`

Returns the absolute path to the directory on the filesystem similar to `https://developer.android.com/reference/android/content/Context.html#getFilesDir()`.
`java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/java/io/File.html!>` `@https://developer.android.com/reference/kotlin/androidx/annotation/ReplaceWith(expression = "context.getObbDirs()")
[getObbDirs](https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getObbDirs(android.content.Context))(context: https://developer.android.com/reference/android/content/Context.html)`

**This function is deprecated.**

Call `https://developer.android.com/reference/android/content/Context.html#getObbDirs()` directly.

<br />

`java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getString(android.content.Context,int)(context: https://developer.android.com/reference/android/content/Context.html, resId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

Gets the resource string that also respects the per-app locales.
`java-static T?` `<T> https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getSystemService(android.content.Context,java.lang.Class<T>)(context: https://developer.android.com/reference/android/content/Context.html, serviceClass: https://developer.android.com/reference/java/lang/Class.html<T!>)`

Return the handle to a system-level service by class.
`java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getSystemServiceName(android.content.Context,java.lang.Class<?>)(context: https://developer.android.com/reference/android/content/Context.html, serviceClass: https://developer.android.com/reference/java/lang/Class.html<*>)`

Gets the name of the system-level service that is represented by the specified class.
`java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#isDeviceProtectedStorage(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)`

Indicates if the storage APIs of this Context are backed by device-encrypted storage.
`java-static https://developer.android.com/reference/android/content/Intent.html?` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)(

context: https://developer.android.com/reference/android/content/Context.html,

receiver: https://developer.android.com/reference/android/content/BroadcastReceiver.html?,

filter: https://developer.android.com/reference/android/content/IntentFilter.html,

flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html

)`

Register a broadcast receiver.
`java-static https://developer.android.com/reference/android/content/Intent.html?` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,java.lang.String,android.os.Handler,int)(

context: https://developer.android.com/reference/android/content/Context.html,

receiver: https://developer.android.com/reference/android/content/BroadcastReceiver.html?,

filter: https://developer.android.com/reference/android/content/IntentFilter.html,

broadcastPermission: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?,

scheduler: https://developer.android.com/reference/android/os/Handler.html?,

flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html

)`

Register a broadcast receiver.
`java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#startActivities(android.content.Context,android.content.Intent[])(context: https://developer.android.com/reference/android/content/Context.html, intents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/android/content/Intent.html!>)`

Start a set of activities as a synthesized task stack, if able.
`java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#startActivities(android.content.Context,android.content.Intent[],android.os.Bundle)(context: https://developer.android.com/reference/android/content/Context.html, intents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/android/content/Intent.html!>, options: https://developer.android.com/reference/android/os/Bundle.html?)`

Start a set of activities as a synthesized task stack, if able.
`java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/annotation/ReplaceWith(expression = "context.startActivity(intent, options)")
[startActivity](https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#startActivity(android.content.Context,android.content.Intent,android.os.Bundle))(context: https://developer.android.com/reference/android/content/Context.html, intent: https://developer.android.com/reference/android/content/Intent.html, options: https://developer.android.com/reference/android/os/Bundle.html?)`

**This function is deprecated.**

Call startActivity directly.

<br />

`java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#startForegroundService(android.content.Context,android.content.Intent)(context: https://developer.android.com/reference/android/content/Context.html, intent: https://developer.android.com/reference/android/content/Intent.html)`

startForegroundService() was introduced in O, just call startService for before O.

## Protected constructors

### ActivityCompat

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
protected ActivityCompat()
```

This class should not be instantiated, but the constructor must be visible for the class to be extended (as in support-v13).

## Public functions

### finishAffinity

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun finishAffinity(activity: Activity): Unit
```

Finish this activity, and tries to finish all activities immediately below it in the current task that have the same affinity.

On Android 4.1+ calling this method will call through to the native version of this method. For other platforms `https://developer.android.com/reference/android/app/Activity.html#finish()` will be called instead.

### finishAfterTransition

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun finishAfterTransition(activity: Activity): Unit
```

Reverses the Activity Scene entry Transition and triggers the calling Activity to reverse its exit Transition. When the exit Transition completes, `https://developer.android.com/reference/android/app/Activity.html#finish()` is called. If no entry Transition was used, finish() is called immediately and the Activity exit Transition is run.

On Android 4.4 or lower, this method only finishes the Activity with no special exit transition.

### getReferrer

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun getReferrer(activity: Activity): Uri?
```

Return information about who launched this activity. If the launching Intent contains an `https://developer.android.com/reference/android/content/Intent.html#EXTRA_REFERRER`, that will be returned as-is; otherwise, if known, an `https://developer.android.com/reference/android/content/Intent.html#URI_ANDROID_APP_SCHEME` referrer URI containing the package name that started the Intent will be returned. This may return null if no referrer can be identified -- it is neither explicitly specified, nor is it known which application package was involved.

If called while inside the handling of `https://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)`, this function will return the referrer that submitted that new intent to the activity. Otherwise, it always returns the referrer of the original Intent.

Note that this is *not* a security feature -- you can not trust the referrer information, applications can spoof it.

### invalidateOptionsMenu

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun [invalidateOptionsMenu](https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#invalidateOptionsMenu(android.app.Activity))(activity: Activity!): Boolean
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Use `https://developer.android.com/reference/android/app/Activity.html#invalidateOptionsMenu()` directly.

Invalidate the activity's options menu, if able.

Before API level 11 (Android 3.0/Honeycomb) the lifecycle of the options menu was controlled primarily by the user's operation of the hardware menu key. When the user presses down on the menu key for the first time the menu was created and prepared by calls to `https://developer.android.com/reference/android/app/Activity.html#onCreateOptionsMenu(android.view.Menu)` and `https://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu(android.view.Menu)` respectively. Subsequent presses of the menu key kept the existing instance of the Menu itself and called `https://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu(android.view.Menu)` to give the activity an opportunity to contextually alter the menu before the menu panel was shown.

In Android 3.0+ the Action Bar forces the options menu to be built early so that items chosen to show as actions may be displayed when the activity first becomes visible. The Activity method invalidateOptionsMenu forces the entire menu to be destroyed and recreated from `https://developer.android.com/reference/android/app/Activity.html#onCreateOptionsMenu(android.view.Menu)`, offering a similar though heavier-weight opportunity to change the menu's contents. Normally this functionality is used to support a changing configuration of Fragments.

Applications may use this support helper to signal a significant change in activity state that should cause the options menu to be rebuilt. If the app is running on an older platform version that does not support menu invalidation the app will still receive `https://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu(android.view.Menu)` the next time the user presses the menu key and this method will return false. If this method returns true the options menu was successfully invalidated.

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html!` | Invalidate the options menu of this activity |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if this operation was supported and it completed; false if it was not available. |

### isLaunchedFromBubble

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
java-static fun isLaunchedFromBubble(activity: Activity): Boolean
```

Indicates whether this activity is launched from a bubble. A bubble is a floating shortcut on the screen that expands to show an activity. If your activity can be used normally or as a bubble, you might use this method to check if the activity is bubbled to modify any behaviour that might be different between the normal activity and the bubbled activity. For example, if you normally cancel the notification associated with the activity when you open the activity, you might not want to do that when you're bubbled as that would remove the bubble.
This method will return for app Bubbles. See https://developer.android.com/develop/ui/compose/layouts/adaptive/support-bubbles and only applicable to chat bubbles.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the activity is launched from a bubble. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Builder#setBubbleMetadata(androidx.core.app.NotificationCompat.BubbleMetadata)` |   |
| `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.BubbleMetadata.Builder#Builder(java.lang.String)` | Compatibility behavior: - API 31 and above, this method matches platform behavior - API 29, 30, this method checks the window display ID - API 28 and earlier, this method is a no-op |

### postponeEnterTransition

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun postponeEnterTransition(activity: Activity): Unit
```

### recreate

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun recreate(activity: Activity): Unit
```

Cause the given Activity to be recreated with a new instance. This version of the method allows a consistent behavior across API levels, emulating what happens on Android Pie (and newer) when running on older platforms.

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html` | The activity to recreate |

### requestDragAndDropPermissions

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun requestDragAndDropPermissions(activity: Activity, dragEvent: DragEvent): DragAndDropPermissionsCompat?
```

Create `https://developer.android.com/reference/kotlin/androidx/core/view/DragAndDropPermissionsCompat` object bound to this activity and controlling the access permissions for content URIs associated with the `https://developer.android.com/reference/android/view/DragEvent.html`.

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html` | activity for which to request the permission. |
| `dragEvent: https://developer.android.com/reference/android/view/DragEvent.html` | Drag event to request permission for |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/view/DragAndDropPermissionsCompat?` | The `https://developer.android.com/reference/kotlin/androidx/core/view/DragAndDropPermissionsCompat` object used to control access to the content URIs. `null` if no content URIs are associated with the event or if permissions could not be granted. |

### requestPermissions

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun requestPermissions(
    activity: Activity,
    permissions: Array<String!>,
    requestCode: @IntRange(from = 0) Int
): Unit
```

Requests permissions to be granted to this application. These permissions must be requested in your manifest, they should not be granted to your app, and they should have protection level `https://developer.android.com/reference/android/content/pm/PermissionInfo.html#PROTECTION_DANGEROUS`, regardless whether they are declared by the platform or a third-party app.

Normal permissions `https://developer.android.com/reference/android/content/pm/PermissionInfo.html#PROTECTION_NORMAL` are granted at install time if requested in the manifest. Signature permissions `https://developer.android.com/reference/android/content/pm/PermissionInfo.html#PROTECTION_SIGNATURE` are granted at install time if requested in the manifest and the signature of your app matches the signature of the app declaring the permissions.

Call `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#shouldShowRequestPermissionRationale(android.app.Activity,java.lang.String)` before calling this API to check if the system recommends to show a rationale dialog before asking for a permission.

If your app does not have the requested permissions the user will be presented with UI for accepting them. After the user has accepted or rejected the requested permissions you will receive a callback reporting whether the permissions were granted or not. Your activity has to implement `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat.OnRequestPermissionsResultCallback` and the results of permission requests will be delivered to its `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int,java.lang.String[],int[])` method.

Note that requesting a permission does not guarantee it will be granted and your app should be able to run without having this permission.

This method may start an activity allowing the user to choose which permissions to grant and which to reject. Hence, you should be prepared that your activity may be paused and resumed. Further, granting some permissions may require a restart of you application. In such a case, the system will recreate the activity stack before delivering the result to your `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int,java.lang.String[],int[])`.

When checking whether you have a permission you should use `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#checkSelfPermission(android.content.Context,java.lang.String)`.

Calling this API for permissions already granted to your app would show UI to the user to decide whether the app can still hold these permissions. This can be useful if the way your app uses the data guarded by the permissions changes significantly.

You cannot request a permission if your activity sets `https://developer.android.com/reference/android/R.attr.html#noHistory` to `true` in the manifest because in this case the activity would not receive result callbacks including `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int,java.lang.String[],int[])`.

The [RuntimePermissions](https://github.com/googlesamples/android-RuntimePermissions) sample app demonstrates how to use this method to request permissions at run time.

If `https://developer.android.com/reference/android/Manifest.permission.html#POST_NOTIFICATIONS` is requested before the device supports the notification permission, then `https://developer.android.com/reference/android/Manifest.permission.html#POST_NOTIFICATIONS` will be removed from `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int,java.lang.String[],int[])`. For devices that don't support `https://developer.android.com/reference/android/Manifest.permission.html#POST_NOTIFICATIONS`, apps can send users to its notification settings to enable notifications. See android.provider.Settings.ACTION_APP_NOTIFICATION_SETTINGS for more information on launching notification settings.

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html` | The target activity. |
| `permissions: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>` | The requested permissions. Must be non-null and not empty. |
| `requestCode: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Application specific request code to match with a result reported to `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int,java.lang.String[],int[])`. Should be \>= 0. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int,java.lang.String[],int[])` |   |
| `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#checkSelfPermission(android.content.Context,java.lang.String)` |   |
| `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#shouldShowRequestPermissionRationale(android.app.Activity,java.lang.String)` |   |

### requireViewById

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun <T : View?> requireViewById(activity: Activity, id: @IdRes Int): T
```

Finds a view that was identified by the `android:id` XML attribute that was processed in `https://developer.android.com/reference/android/app/Activity.html#onCreate(android.os.Bundle)`, or throws an IllegalArgumentException if the ID is invalid, or there is no matching view in the hierarchy.

**Note:** In most cases -- depending on compiler support -- the resulting view is automatically cast to the target class type. If the target class type is unconstrained, an explicit cast may be necessary.

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html` | activity in which to find a view. |
| `id: @https://developer.android.com/reference/kotlin/androidx/annotation/IdRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the ID to search for |

| Returns |
|---|---|
| `T` | a view with given ID |

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/Activity.html#findViewById(int)` |   |
| `https://developer.android.com/reference/kotlin/androidx/core/view/ViewCompat#requireViewById(android.view.View,int)` |   |

### setEnterSharedElementCallback

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun setEnterSharedElementCallback(
    activity: Activity,
    callback: SharedElementCallback?
): Unit
```

When `https://developer.android.com/reference/android/app/ActivityOptions.html#makeSceneTransitionAnimation(android.app.Activity, android.view.View, java.lang.String)` was used to start an Activity, <var translate="no">callback</var> will be called to handle shared elements on the *launched* Activity. This requires `https://developer.android.com/reference/android/view/Window.html#FEATURE_CONTENT_TRANSITIONS`.

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html` | activity for which to set the callback. |
| `callback: https://developer.android.com/reference/kotlin/androidx/core/app/SharedElementCallback?` | Used to manipulate shared element transitions on the launched Activity. |

### setExitSharedElementCallback

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun setExitSharedElementCallback(
    activity: Activity,
    callback: SharedElementCallback?
): Unit
```

When `https://developer.android.com/reference/android/app/ActivityOptions.html#makeSceneTransitionAnimation(android.app.Activity, android.view.View, java.lang.String)` was used to start an Activity, <var translate="no">callback</var> will be called to handle shared elements on the *launching* Activity. Most calls will only come when returning from the started Activity. This requires `https://developer.android.com/reference/android/view/Window.html#FEATURE_CONTENT_TRANSITIONS`.

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html` | activity for which to set the callback. |
| `callback: https://developer.android.com/reference/kotlin/androidx/core/app/SharedElementCallback?` | Used to manipulate shared element transitions on the launching Activity. |

### setLocusContext

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/core#1.5.0)

```
java-static fun setLocusContext(activity: Activity, locusId: LocusIdCompat?, bundle: Bundle?): Unit
```

Sets the `https://developer.android.com/reference/kotlin/androidx/core/content/LocusIdCompat` for this activity. The locus id helps identify different instances of the same `Activity` class.

For example, a locus id based on a specific conversation could be set on a conversation app's chat `Activity`. The system can then use this locus id along with app's contents to provide ranking signals in various UI surfaces including sharing, notifications, shortcuts and so on.

It is recommended to set the same locus id in the shortcut's locus id using `https://developer.android.com/reference/kotlin/androidx/core/content/pm/ShortcutInfoCompat.Builder#setLocusId(androidx.core.content.LocusIdCompat)` so that the system can learn appropriate ranking signals linking the activity's locus id with the matching shortcut.

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html` | activity for which to set locus id. |
| `locusId: https://developer.android.com/reference/kotlin/androidx/core/content/LocusIdCompat?` | a unique, stable id that identifies this `Activity` instance. LocusId is an opaque ID that links this Activity's state to different Android concepts: `https://developer.android.com/reference/kotlin/androidx/core/content/pm/ShortcutInfoCompat.Builder#setLocusId(androidx.core.content.LocusIdCompat)`. LocusID is null by default or if you explicitly reset it. |
| `bundle: https://developer.android.com/reference/android/os/Bundle.html?` | extras set or updated as part of this locus context. This may help provide additional metadata such as URLs, conversation participants specific to this `Activity`'s context. Bundle can be null if additional metadata is not needed. Bundle should always be null for null locusId. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureManager.html` |   |
| `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureContext.html` | Compatibility behavior: - API 30 and above, this method matches platform behavior. - API 29 and earlier, this method is no-op. |

### setPermissionCompatDelegate

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun setPermissionCompatDelegate(
    delegate: ActivityCompat.PermissionCompatDelegate?
): Unit
```

Sets the permission delegate for `ActivityCompat`. Replaces the previously set delegate.

| Parameters |
|---|---|
| `delegate: https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat.PermissionCompatDelegate?` | The delegate to be set. `null` to clear the set delegate. |

### shouldShowRequestPermissionRationale

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun shouldShowRequestPermissionRationale(
    activity: Activity,
    permission: String
): Boolean
```

Gets whether you should show UI with rationale before requesting a permission.

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html` | The target activity. |
| `permission: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | A permission your app wants to request. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether you should show permission rationale UI. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#checkSelfPermission(android.content.Context,java.lang.String)` |   |
| `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityCompat#requestPermissions(android.app.Activity,java.lang.String[],int)` |   |

### startActivityForResult

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun startActivityForResult(
    activity: Activity,
    intent: Intent,
    requestCode: Int,
    options: Bundle?
): Unit
```

Start new activity with options, if able, for which you would like a result when it finished.

In Android 4.1+ additional options were introduced to allow for more control on activity launch animations. Applications can use this method along with `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityOptionsCompat` to use these animations when available. When run on versions of the platform where this feature does not exist the activity will be launched normally.

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html` | Origin activity to launch from. |
| `intent: https://developer.android.com/reference/android/content/Intent.html` | The description of the activity to start. |
| `requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | If \>= 0, this code will be returned in onActivityResult() when the activity exits. |
| `options: https://developer.android.com/reference/android/os/Bundle.html?` | Additional options for how the Activity should be started. May be null if there are no options. See `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityOptionsCompat` for how to build the Bundle supplied here; there are no supported definitions for building it manually. |

### startIntentSenderForResult

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun startIntentSenderForResult(
    activity: Activity,
    intent: IntentSender,
    requestCode: Int,
    fillInIntent: Intent?,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int,
    options: Bundle?
): Unit
```

Start new IntentSender with options, if able, for which you would like a result when it finished.

In Android 4.1+ additional options were introduced to allow for more control on activity launch animations. Applications can use this method along with `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityOptionsCompat` to use these animations when available. When run on versions of the platform where this feature does not exist the activity will be launched normally.

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html` | Origin activity to launch from. |
| `intent: https://developer.android.com/reference/android/content/IntentSender.html` | The IntentSender to launch. |
| `requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | If \>= 0, this code will be returned in onActivityResult() when the activity exits. |
| `fillInIntent: https://developer.android.com/reference/android/content/Intent.html?` | If non-null, this will be provided as the intent parameter to `https://developer.android.com/reference/android/content/IntentSender.html#sendIntent(android.content.Context, int, android.content.Intent, android.content.IntentSender.OnFinished, android.os.Handler)`. |
| `flagsMask: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Intent flags in the original IntentSender that you would like to change. |
| `flagsValues: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Desired values for any bits set in <var translate="no">flagsMask</var> |
| `extraFlags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Always set to 0. |
| `options: https://developer.android.com/reference/android/os/Bundle.html?` | Additional options for how the Activity should be started. May be null if there are no options. See `https://developer.android.com/reference/kotlin/androidx/core/app/ActivityOptionsCompat` for how to build the Bundle supplied here; there are no supported definitions for building it manually. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/content/IntentSender.SendIntentException.html` |   |

### startPostponedEnterTransition

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun startPostponedEnterTransition(activity: Activity): Unit
```