# ContextCompat

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

*** ** * ** ***


```
public class ContextCompat
```

<br />

Known direct subclasses [ActivityCompat](https://developer.android.com/reference/androidx/core/app/ActivityCompat)

|---|---|
| `https://developer.android.com/reference/androidx/core/app/ActivityCompat` | Helper for accessing features in `https://developer.android.com/reference/android/app/Activity.html`. |

*** ** * ** ***

Helper for accessing features in `https://developer.android.com/reference/android/content/Context.html`.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#RECEIVER_EXPORTED() = 2` Flag for `https://developer.android.com/reference/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)`: The receiver can receive broadcasts from other Apps. |
| `static final int` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#RECEIVER_NOT_EXPORTED() = 4` Flag for `https://developer.android.com/reference/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)`: The receiver cannot receive broadcasts from other Apps. |
| `static final int` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#RECEIVER_VISIBLE_TO_INSTANT_APPS() = 1` Flag for `https://developer.android.com/reference/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)`: The receiver can receive broadcasts from Instant Apps. |

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

| ### Public methods |
|---|---|
| `static int` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#checkSelfPermission(android.content.Context,java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission)` Determine whether *you* have been granted a particular permission. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#createAttributionContext(android.content.Context,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html attributionTag )` Return a new Context object for the current Context but attribute to a different tag. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/Context.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#createDeviceProtectedStorageContext(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Return a new Context object for the current Context but whose storage APIs are backed by device-protected storage. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#getAttributionTag(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Attribution can be used in complex apps to logically separate parts of the app. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/io/File.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#getCodeCacheDir(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Returns the absolute path to the application specific cache directory on the filesystem designed for storing cached code. |
| `static @https://developer.android.com/reference/androidx/annotation/ColorInt int` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#getColor(android.content.Context,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/ColorRes int id)` Returns a color associated with a particular resource ID |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/res/ColorStateList.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#getColorStateList(android.content.Context,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/ColorRes int id)` Returns a color state list associated with a particular resource ID. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#getContextForLanguage(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Gets the context which respects the per-app locales locale. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/io/File.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#getDataDir(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Returns the absolute path to the directory on the filesystem where all private files belonging to this app are stored. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/Display.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#getDisplayOrDefault(android.content.Context)(@https://developer.android.com/reference/androidx/annotation/DisplayContext @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` 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`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#getDrawable(android.content.Context,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/DrawableRes int id)` Returns a drawable object associated with a particular resource ID. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html File[]` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "context.getExternalCacheDirs()") [getExternalCacheDirs](https://developer.android.com/reference/androidx/core/content/ContextCompat#getExternalCacheDirs(android.content.Context))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` **This method is deprecated.** Call `https://developer.android.com/reference/android/content/Context.html#getExternalCacheDirs()` directly. <br /> |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html File[]` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "context.getExternalFilesDirs(type)") [getExternalFilesDirs](https://developer.android.com/reference/androidx/core/content/ContextCompat#getExternalFilesDirs(android.content.Context,java.lang.String))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html type)` **This method is deprecated.** Call getExternalFilesDirs directly. <br /> |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#getMainExecutor(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` 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. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/io/File.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#getNoBackupFilesDir(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Returns the absolute path to the directory on the filesystem similar to `https://developer.android.com/reference/android/content/Context.html#getFilesDir()`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html File[]` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "context.getObbDirs()") [getObbDirs](https://developer.android.com/reference/androidx/core/content/ContextCompat#getObbDirs(android.content.Context))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` **This method is deprecated.** Call `https://developer.android.com/reference/android/content/Context.html#getObbDirs()` directly. <br /> |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#getString(android.content.Context,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, int resId)` Gets the resource string that also respects the per-app locales. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html T` | `<T> https://developer.android.com/reference/androidx/core/content/ContextCompat#getSystemService(android.content.Context,java.lang.Class<T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> serviceClass )` Return the handle to a system-level service by class. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#getSystemServiceName(android.content.Context,java.lang.Class<?>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> serviceClass )` Gets the name of the system-level service that is represented by the specified class. |
| `static boolean` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#isDeviceProtectedStorage(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Indicates if the storage APIs of this Context are backed by device-encrypted storage. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/Intent.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/BroadcastReceiver.html receiver, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/IntentFilter.html filter, int flags )` Register a broadcast receiver. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/Intent.html` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,java.lang.String,android.os.Handler,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/BroadcastReceiver.html receiver, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/IntentFilter.html filter, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html broadcastPermission, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Handler.html scheduler, int flags )` Register a broadcast receiver. |
| `static boolean` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#startActivities(android.content.Context,android.content.Intent[])(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html Intent[] intents)` Start a set of activities as a synthesized task stack, if able. |
| `static boolean` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#startActivities(android.content.Context,android.content.Intent[],android.os.Bundle)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html Intent[] intents, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Bundle.html options )` Start a set of activities as a synthesized task stack, if able. |
| `static void` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "context.startActivity(intent, options)") [startActivity](https://developer.android.com/reference/androidx/core/content/ContextCompat#startActivity(android.content.Context,android.content.Intent,android.os.Bundle))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html intent, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Bundle.html options )` **This method is deprecated.** Call startActivity directly. <br /> |
| `static void` | `https://developer.android.com/reference/androidx/core/content/ContextCompat#startForegroundService(android.content.Context,android.content.Intent)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html intent)` startForegroundService() was introduced in O, just call startService for before O. |

## Constants

### RECEIVER_EXPORTED

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

```
public static final int RECEIVER_EXPORTED = 2
```

Flag for `https://developer.android.com/reference/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)`: The receiver can receive broadcasts from other Apps. Has the same behavior as marking a statically registered receiver with "exported=true"

### RECEIVER_NOT_EXPORTED

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

```
public static final int RECEIVER_NOT_EXPORTED = 4
```

Flag for `https://developer.android.com/reference/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)`: The receiver cannot receive broadcasts from other Apps. Has the same behavior as marking a statically registered receiver with "exported=false"

### RECEIVER_VISIBLE_TO_INSTANT_APPS

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

```
public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 1
```

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

## Protected constructors

### ContextCompat

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

```
protected ContextCompat()
```

This class should not be instantiated, but the constructor must be visible for the class to be extended (ex. in ActivityCompat).

## Public methods

### checkSelfPermission

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

```
public static int checkSelfPermission(@NonNull Context context, @NonNull String permission)
```

Determine whether *you* have been granted a particular permission.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | context for which to check the permission. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission` | The name of the permission being checked. |

| Returns |
|---|---|
| `int` | `https://developer.android.com/reference/android/content/pm/PackageManager.html#PERMISSION_GRANTED` if you have the permission, or `https://developer.android.com/reference/android/content/pm/PackageManager.html#PERMISSION_DENIED` if not. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/pm/PackageManager.html#checkPermission(java.lang.String, java.lang.String)` |   |

### createAttributionContext

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

```
public static @NonNull Context createAttributionContext(
    @NonNull Context context,
    @Nullable String attributionTag
)
```

Return a new Context object for the current Context but attribute to a different tag. In complex apps attribution tagging can be used to distinguish between separate logical parts.

Compatibility behavior:

- API 30 and above, returns a new Context object with the specified attribution tag
- API 29 and earlier, returns the original `context` with no attribution tag

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | The current context. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html attributionTag` | The tag or `null` to create a context for the default. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html` | A `https://developer.android.com/reference/android/content/Context.html` that is tagged for the new attribution |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/content/ContextCompat#getAttributionTag(android.content.Context)` |   |

### createDeviceProtectedStorageContext

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

```
public static @Nullable Context createDeviceProtectedStorageContext(@NonNull Context context)
```

Return a new Context object for the current Context but whose storage APIs are backed by device-protected storage.

On devices with direct boot, data stored in this location is encrypted with a key tied to the physical device, and it can be accessed immediately after the device has booted successfully, both *before and after* the user has authenticated with their credentials (such as a lock pattern or PIN).

Because device-protected data is available without user authentication, you should carefully limit the data you store using this Context. For example, storing sensitive authentication tokens or passwords in the device-protected area is strongly discouraged.

If the underlying device does not have the ability to store device-protected and credential-protected data using different keys, then both storage areas will become available at the same time. They remain as two distinct storage locations on disk, and only the window of availability changes.

Each call to this method returns a new instance of a Context object; Context objects are not shared, however common state (ClassLoader, other Resources for the same configuration) may be so the Context itself can be fairly lightweight.

Prior to API 24 this method returns `null`, since device-protected storage is not available.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/content/ContextCompat#isDeviceProtectedStorage(android.content.Context)` |   |

### getAttributionTag

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

```
public static @Nullable String getAttributionTag(@NonNull Context context)
```

Attribution can be used in complex apps to logically separate parts of the app. E.g. a blogging app might also have a instant messaging app built in. In this case two separate tags can for used each sub-feature.

Compatibility behavior:

- API 30 and above, returns the attribution tag or `null`
- API 29 and earlier, returns `null`

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | the attribution tag this context is for or `null` if this is the default. |

### getCodeCacheDir

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

```
public static @NonNull File getCodeCacheDir(@NonNull Context context)
```

Returns the absolute path to the application specific cache directory on the filesystem designed for storing cached code. On devices running `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#LOLLIPOP` or later, the system will delete any files stored in this location both when your specific application is upgraded, and when the entire platform is upgraded.

This location is optimal for storing compiled or optimized code generated by your application at runtime.

Apps require no extra permissions to read or write to the returned path, since this path lives in their private storage.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/io/File.html` | The path of the directory holding application code cache files. |

### getColor

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

```
public static @ColorInt int getColor(@NonNull Context context, @ColorRes int id)
```

Returns a color associated with a particular resource ID

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#M`, the returned color will be styled for the specified Context's theme.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | context to use for getting the color. |
| `@https://developer.android.com/reference/androidx/annotation/ColorRes int id` | The desired resource identifier, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int` | A single color value in the form 0xAARRGGBB. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/content/res/Resources.NotFoundException.html` | if the given ID does not exist. |

### getColorStateList

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

```
public static @Nullable ColorStateList getColorStateList(@NonNull Context context, @ColorRes int id)
```

Returns a color state list associated with a particular resource ID.

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#M`, the returned color state list will be styled for the specified Context's theme.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | context to use for getting the color state list. |
| `@https://developer.android.com/reference/androidx/annotation/ColorRes int id` | The desired resource identifier, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/res/ColorStateList.html` | A color state list, or `null` if the resource could not be resolved. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/content/res/Resources.NotFoundException.html` | if the given ID does not exist. |

### getContextForLanguage

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

```
public static @NonNull Context getContextForLanguage(@NonNull Context context)
```

Gets the context which respects the per-app locales locale. This API is specifically for developers who set the per-app locales via `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDelegate#setApplicationLocales(androidx.core.os.LocaleListCompat)`, but who needs to use the context out of `https://developer.android.com/reference/androidx/appcompat/app/AppCompatActivity` scope.

The developers can override the returned context in Application's `https://developer.android.com/reference/android/content/ContextWrapper.html#attachBaseContext(android.content.Context)`, so that developers can get the localized string via application's context.

Compatibility behavior:

- API 17 and above, the locale in the context returned by this method will respect the the per-app locale.
- API 16 and earlier, this method directly return the `https://developer.android.com/reference/android/content/Context.html`

### getDataDir

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

```
public static @Nullable File getDataDir(@NonNull Context context)
```

Returns the absolute path to the directory on the filesystem where all private files belonging to this app are stored. Apps should not use this path directly; they should instead use `https://developer.android.com/reference/android/content/Context.html#getFilesDir()`, `https://developer.android.com/reference/android/content/Context.html#getCacheDir()`, `https://developer.android.com/reference/android/content/Context.html#getDir(java.lang.String, int)`, or other storage APIs on `https://developer.android.com/reference/android/content/Context.html`.

The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.

No additional permissions are required for the calling app to read or write files under the returned path.

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/pm/ApplicationInfo.html#dataDir` |   |

### getDisplayOrDefault

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

```
public static @NonNull Display getDisplayOrDefault(@DisplayContext @NonNull Context context)
```

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

Applications must use this method with `https://developer.android.com/reference/android/app/Activity.html` or a context associated with a `https://developer.android.com/reference/android/view/Display.html` via `https://developer.android.com/reference/android/content/Context.html#createDisplayContext(android.view.Display)` or `https://developer.android.com/reference/android/content/Context.html#createWindowContext(android.view.Display, int, android.os.Bundle)`, or the reported `https://developer.android.com/reference/android/view/Display.html` instance is not reliable.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/DisplayContext @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Context to obtain the associated display |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/Display.html` | The display associated with the Context or the default display if the context doesn't associated with any display. |

### getDrawable

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

```
public static @Nullable Drawable getDrawable(@NonNull Context context, @DrawableRes int id)
```

Returns a drawable object associated with a particular resource ID.

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#LOLLIPOP`, the returned drawable will be styled for the specified Context's theme.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | context to use for getting the drawable. |
| `@https://developer.android.com/reference/androidx/annotation/DrawableRes int id` | The desired resource identifier, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | Drawable An object that can be used to draw this resource. |

### getExternalCacheDirs

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

```
@ReplaceWith(expression = "context.getExternalCacheDirs()")
public static @NonNull File[] [getExternalCacheDirs](https://developer.android.com/reference/androidx/core/content/ContextCompat#getExternalCacheDirs(android.content.Context))(@NonNull Context context)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Call `https://developer.android.com/reference/android/content/Context.html#getExternalCacheDirs()` directly.

Returns absolute paths to application-specific directories on all external storage devices where the application can place cache files it owns. These files are internal to the application, and not typically visible to the user as media.

This is like `https://developer.android.com/reference/android/content/Context.html#getCacheDir()` in that these files will be deleted when the application is uninstalled, however there are some important differences:

- External files are not always available: they will disappear if the user mounts the external storage on a computer or removes it.
- There is no security enforced with these files.

External storage devices returned here are considered a permanent part of the device, including both emulated external storage and physical media slots, such as SD cards in a battery compartment. The returned paths do not include transient devices, such as USB flash drives.

An application may store data on any or all of the returned devices. For example, an app may choose to store large files on the device with the most available space, as measured by `https://developer.android.com/reference/android/os/StatFs.html`.

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#KITKAT`, no permissions are required to write to the returned paths; they're always accessible to the calling app. Before then, `https://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE` is required to write. Write access outside of these paths on secondary external storage devices is not available. To request external storage access in a backwards compatible way, consider using `android:maxSdkVersion` like this:

```
<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
```

The first path returned is the same as `https://developer.android.com/reference/android/content/Context.html#getExternalCacheDir()`. Returned paths may be `null` if a storage device is unavailable.

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#getExternalCacheDir()` |   |
| `https://developer.android.com/reference/androidx/core/os/EnvironmentCompat#getStorageState(java.io.File)` |   |

### getExternalFilesDirs

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

```
@ReplaceWith(expression = "context.getExternalFilesDirs(type)")
public static @NonNull File[] [getExternalFilesDirs](https://developer.android.com/reference/androidx/core/content/ContextCompat#getExternalFilesDirs(android.content.Context,java.lang.String))(@NonNull Context context, @Nullable String type)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Call getExternalFilesDirs directly.

Returns absolute paths to application-specific directories on all external storage devices where the application can place persistent files it owns. These files are internal to the application, and not typically visible to the user as media.

This is like `https://developer.android.com/reference/android/content/Context.html#getFilesDir()` in that these files will be deleted when the application is uninstalled, however there are some important differences:

- External files are not always available: they will disappear if the user mounts the external storage on a computer or removes it.
- There is no security enforced with these files.

External storage devices returned here are considered a permanent part of the device, including both emulated external storage and physical media slots, such as SD cards in a battery compartment. The returned paths do not include transient devices, such as USB flash drives.

An application may store data on any or all of the returned devices. For example, an app may choose to store large files on the device with the most available space, as measured by `https://developer.android.com/reference/android/os/StatFs.html`.

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#KITKAT`, no permissions are required to write to the returned paths; they're always accessible to the calling app. Before then, `https://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE` is required to write. Write access outside of these paths on secondary external storage devices is not available. To request external storage access in a backwards compatible way, consider using `android:maxSdkVersion` like this:

```
<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
```

The first path returned is the same as `https://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)`. Returned paths may be `null` if a storage device is unavailable.

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)` |   |
| `https://developer.android.com/reference/androidx/core/os/EnvironmentCompat#getStorageState(java.io.File)` |   |

### getMainExecutor

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

```
public static @NonNull Executor getMainExecutor(@NonNull Context context)
```

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. This is the thread used to dispatch calls to application components (activities, services, etc).

### getNoBackupFilesDir

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

```
public static @Nullable File getNoBackupFilesDir(@NonNull Context context)
```

Returns the absolute path to the directory on the filesystem similar to `https://developer.android.com/reference/android/content/Context.html#getFilesDir()`. The difference is that files placed under this directory will be excluded from automatic backup to remote storage on devices running `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#LOLLIPOP` or later.

No permissions are required to read or write to the returned path, since this path is internal storage.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/io/File.html` | The path of the directory holding application files that will not be automatically backed up to remote storage. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#getFilesDir()` |   |

### getObbDirs

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

```
@ReplaceWith(expression = "context.getObbDirs()")
public static @NonNull File[] [getObbDirs](https://developer.android.com/reference/androidx/core/content/ContextCompat#getObbDirs(android.content.Context))(@NonNull Context context)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Call `https://developer.android.com/reference/android/content/Context.html#getObbDirs()` directly.

Returns absolute paths to application-specific directories on all external storage devices where the application's OBB files (if there are any) can be found. Note if the application does not have any OBB files, these directories may not exist.

This is like `https://developer.android.com/reference/android/content/Context.html#getFilesDir()` in that these files will be deleted when the application is uninstalled, however there are some important differences:

- External files are not always available: they will disappear if the user mounts the external storage on a computer or removes it.
- There is no security enforced with these files.

External storage devices returned here are considered a permanent part of the device, including both emulated external storage and physical media slots, such as SD cards in a battery compartment. The returned paths do not include transient devices, such as USB flash drives.

An application may store data on any or all of the returned devices. For example, an app may choose to store large files on the device with the most available space, as measured by `https://developer.android.com/reference/android/os/StatFs.html`.

Starting in `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#KITKAT`, no permissions are required to write to the returned paths; they're always accessible to the calling app. Before then, `https://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE` is required to write. Write access outside of these paths on secondary external storage devices is not available. To request external storage access in a backwards compatible way, consider using `android:maxSdkVersion` like this:

```
<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
```

The first path returned is the same as `https://developer.android.com/reference/android/content/Context.html#getObbDir()`. Returned paths may be `null` if a storage device is unavailable.

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#getObbDir()` |   |
| `https://developer.android.com/reference/androidx/core/os/EnvironmentCompat#getStorageState(java.io.File)` |   |

### getString

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

```
public static @NonNull String getString(@NonNull Context context, int resId)
```

Gets the resource string that also respects the per-app locales. If developers set the per-app locales via `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDelegate#setApplicationLocales(androidx.core.os.LocaleListCompat)`, this API returns localized strings even if the context is not `https://developer.android.com/reference/androidx/appcompat/app/AppCompatActivity`.

Compatibility behavior:

- API 17 and above, this method return the localized string that respects per-app locales.
- API 16 and earlier, this method directly return the result of `https://developer.android.com/reference/android/content/Context.html#getString(int)`

### getSystemService

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

```
public static @Nullable T <T> getSystemService(
    @NonNull Context context,
    @NonNull Class<T> serviceClass
)
```

Return the handle to a system-level service by class.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Context to retrieve service from. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> serviceClass` | The class of the desired service. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html T` | The service or null if the class is not a supported system service. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#getSystemService(java.lang.Class&lt;T&gt;)` |   |

### getSystemServiceName

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

```
public static @Nullable String getSystemServiceName(
    @NonNull Context context,
    @NonNull Class<@NonNull ?> serviceClass
)
```

Gets the name of the system-level service that is represented by the specified class.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Context to retrieve service name from. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> serviceClass` | The class of the desired service. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | The service name or null if the class is not a supported system service. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#getSystemServiceName(java.lang.Class&lt;?&gt;)` |   |

### isDeviceProtectedStorage

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

```
public static boolean isDeviceProtectedStorage(@NonNull Context context)
```

Indicates if the storage APIs of this Context are backed by device-encrypted storage.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/content/ContextCompat#createDeviceProtectedStorageContext(android.content.Context)` |   |

### registerReceiver

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

```
public static @Nullable Intent registerReceiver(
    @NonNull Context context,
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    int flags
)
```

Register a broadcast receiver.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/BroadcastReceiver.html receiver` | The BroadcastReceiver to handle the broadcast. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Context to retrieve service from. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/IntentFilter.html filter` | Selects the Intent broadcasts to be received. |
| `int flags` | If this receiver is listening for broadcasts sent from other apps---even other apps that you own---use the `https://developer.android.com/reference/androidx/core/content/ContextCompat#RECEIVER_EXPORTED()` flag. If instead this receiver is listening only for broadcasts sent by your app, or from the system UID, use the `https://developer.android.com/reference/androidx/core/content/ContextCompat#RECEIVER_NOT_EXPORTED()` flag. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/Intent.html` | The first sticky intent found that matches <var translate="no">filter</var>, or null if there are none. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter, int)` |   |
| `https` | ://developer.android.com/develop/background-work/background-tasks/broadcasts#context-registered-receivers |

### registerReceiver

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

```
public static @Nullable Intent registerReceiver(
    @NonNull Context context,
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    @Nullable String broadcastPermission,
    @Nullable Handler scheduler,
    int flags
)
```

Register a broadcast receiver.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/BroadcastReceiver.html receiver` | The BroadcastReceiver to handle the broadcast. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Context to retrieve service from. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/IntentFilter.html filter` | Selects the Intent broadcasts to be received. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html broadcastPermission` | String naming a permission that a broadcaster must hold in order to send and Intent to you. If null, no permission is required. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Handler.html scheduler` | Handler identifying the thread will receive the Intent. If null, the main thread of the process will be used. |
| `int flags` | If this receiver is listening for broadcasts sent from other apps---even other apps that you own---use the `https://developer.android.com/reference/androidx/core/content/ContextCompat#RECEIVER_EXPORTED()` flag. If instead this receiver is listening only for broadcasts sent by your app, or from the system UID, use the `https://developer.android.com/reference/androidx/core/content/ContextCompat#RECEIVER_NOT_EXPORTED()` flag. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/Intent.html` | The first sticky intent found that matches <var translate="no">filter</var>, or null if there are none. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter, java.lang.String, android.os.Handler, int)` |   |
| `https` | ://developer.android.com/develop/background-work/background-tasks/broadcasts#context-registered-receivers |

### startActivities

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

```
public static boolean startActivities(@NonNull Context context, @NonNull Intent[] intents)
```

Start a set of activities as a synthesized task stack, if able.

In API level 11 (Android 3.0/Honeycomb) the recommended conventions for app navigation using the back key changed. The back key's behavior is local to the current task and does not capture navigation across different tasks. Navigating across tasks and easily reaching the previous task is accomplished through the "recents" UI, accessible through the software-provided Recents key on the navigation or system bar. On devices with the older hardware button configuration the recents UI can be accessed with a long press on the Home key.

When crossing from one task stack to another post-Android 3.0, the application should synthesize a back stack/history for the new task so that the user may navigate out of the new task and back to the Launcher by repeated presses of the back key. Back key presses should not navigate across task stacks.

startActivities provides a mechanism for constructing a synthetic task stack of multiple activities. If the underlying API is not available on the system this method will return false.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Start activities using this activity as the starting context |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html Intent[] intents` | Array of intents defining the activities that will be started. The element length-1 will correspond to the top activity on the resulting task stack. |

| Returns |
|---|---|
| `boolean` | true if the underlying API was available and the call was successful, false otherwise |

### startActivities

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

```
public static boolean startActivities(
    @NonNull Context context,
    @NonNull Intent[] intents,
    @Nullable Bundle options
)
```

Start a set of activities as a synthesized task stack, if able.

In API level 11 (Android 3.0/Honeycomb) the recommended conventions for app navigation using the back key changed. The back key's behavior is local to the current task and does not capture navigation across different tasks. Navigating across tasks and easily reaching the previous task is accomplished through the "recents" UI, accessible through the software-provided Recents key on the navigation or system bar. On devices with the older hardware button configuration the recents UI can be accessed with a long press on the Home key.

When crossing from one task stack to another post-Android 3.0, the application should synthesize a back stack/history for the new task so that the user may navigate out of the new task and back to the Launcher by repeated presses of the back key. Back key presses should not navigate across task stacks.

startActivities provides a mechanism for constructing a synthetic task stack of multiple activities. If the underlying API is not available on the system this method will return false.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Start activities using this activity as the starting context |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html Intent[] intents` | Array of intents defining the activities that will be started. The element length-1 will correspond to the top activity on the resulting task stack. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Bundle.html options` | Additional options for how the Activity should be started. See `https://developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent, android.os.Bundle)` |

| Returns |
|---|---|
| `boolean` | true if the underlying API was available and the call was successful, false otherwise |

### startActivity

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

```
@ReplaceWith(expression = "context.startActivity(intent, options)")
public static void [startActivity](https://developer.android.com/reference/androidx/core/content/ContextCompat#startActivity(android.content.Context,android.content.Intent,android.os.Bundle))(
    @NonNull Context context,
    @NonNull Intent intent,
    @Nullable Bundle options
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Call startActivity directly.

Start an activity with additional launch information, if able.

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/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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Context to launch activity from. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html intent` | The description of the activity to start. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Bundle.html options` | Additional options for how the Activity should be started. May be null if there are no options. See `https://developer.android.com/reference/androidx/core/app/ActivityOptionsCompat` for how to build the Bundle supplied here; there are no supported definitions for building it manually. |

### startForegroundService

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

```
public static void startForegroundService(@NonNull Context context, @NonNull Intent intent)
```

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Context to start Service from. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html intent` | The description of the Service to start. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#startForegroundService(android.content.Intent)` |   |
| `https://developer.android.com/reference/android/content/Context.html#startService(android.content.Intent)` |   |