# LifecycleCameraProvider

Artifact: [androidx.camera:camera-lifecycle](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/lifecycle/LifecycleCameraProvider.kt+class:androidx.camera.lifecycle.LifecycleCameraProvider) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

*** ** * ** ***

<br />

```
@ExperimentalCameraProviderConfiguration
interface LifecycleCameraProvider : CameraProvider
```

<br />

*** ** * ** ***

Provides access to a camera which has its opening and closing controlled by a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`.

This allows configuring multiple instances with different `https://developer.android.com/reference/android/content/Context.html` and `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig`. The use cases can be bound to different camera providers simultaneously, but only one `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` can be `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#RESUMED` at a time.

The sample shows how to configure and create two camera providers differently.

```kotlin
import androidx.camera.camera2.Camera2Config
import androidx.camera.core.CameraSelector
import androidx.camera.core.CameraXConfig
import androidx.camera.lifecycle.LifecycleCameraProvider

val cameraProvider1 =
    LifecycleCameraProvider.createInstance(
        context1,
        CameraXConfig.Builder.fromConfig(Camera2Config.defaultConfig())
            .setCameraExecutor(executor1)
            .build(),
    )
cameraProvider1.bindToLifecycle(lifecycleOwner1, CameraSelector.DEFAULT_FRONT_CAMERA, useCase1)

// Switch to different lifecycle owner.

val cameraProvider2 =
    LifecycleCameraProvider.createInstance(
        context2,
        CameraXConfig.Builder.fromConfig(Camera2Config.defaultConfig())
            .setCameraExecutor(executor2)
            .build(),
    )
cameraProvider2.bindToLifecycle(lifecycleOwner2, CameraSelector.DEFAULT_BACK_CAMERA, useCase2)
```

## Summary

| ### Public companion functions |
|---|---|
| `suspend https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider` | `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#createInstance(android.content.Context,androidx.camera.core.CameraXConfig)(context: https://developer.android.com/reference/android/content/Context.html, cameraXConfig: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig?)` Creates a lifecycle camera provider instance. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider>` | `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#createInstanceAsync(android.content.Context,androidx.camera.core.CameraXConfig)(context: https://developer.android.com/reference/android/content/Context.html, cameraXConfig: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig?)` Creates a lifecycle camera provider instance asynchronously. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera` | `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#bindToLifecycle(kotlin.collections.List)( singleCameraConfigs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera.SingleCameraConfig?> )` Binds list of `https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera.SingleCameraConfig`s to `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/Camera` | `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,androidx.camera.core.SessionConfig)( lifecycleOwner: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner, cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector, sessionConfig: https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig )` Binds a `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` to a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/Camera` | `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,androidx.camera.core.UseCaseGroup)( lifecycleOwner: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner, cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector, useCaseGroup: https://developer.android.com/reference/kotlin/androidx/camera/core/UseCaseGroup )` Binds a `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCaseGroup` to a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/Camera` | `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,kotlin.Array)( lifecycleOwner: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner, cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector, vararg useCases: https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase? )` Binds the collection of `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` to a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#isBound(androidx.camera.core.SessionConfig)(sessionConfig: https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig)` Returns `true` if the exact same instance of `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` is bound to a lifecycle, `false` otherwise. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#isBound(androidx.camera.core.UseCase)(useCase: https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase)` Returns `true` if this `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` is bound to a lifecycle or included in a bound `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig`, `false` otherwise. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#unbind(androidx.camera.core.SessionConfig)(sessionConfig: https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig)` Unbinds the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` instance from the lifecycle provider. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#unbind(kotlin.Array)(vararg useCases: https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase?)` Unbinds all specified use cases from the lifecycle provider. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#unbindAll()()` Unbinds all use cases from the lifecycle provider and removes them from CameraX. |

### Inherited functions

From [androidx.camera.core.CameraProvider](https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider) `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#addCameraPresenceListener(java.util.concurrent.Executor,androidx.camera.core.CameraPresenceListener)(

executor: https://developer.android.com/reference/java/util/concurrent/Executor.html,

listener: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraPresenceListener

)`

Adds a listener for changes in camera presence.
`open https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#getCameraInfo(androidx.camera.core.CameraSelector)(cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector)`

Returns the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` instance of the camera resulted from the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector`.
`open https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#getCameraInfo(androidx.camera.core.CameraSelector,androidx.camera.core.SessionConfig)(

cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector,

sessionConfig: https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig

)`

Returns the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` instance of the camera resulted from the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` and `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig`.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#hasCamera(androidx.camera.core.CameraSelector)(cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector)`

Checks whether this provider supports at least one camera that meets the requirements from a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector`.
`open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#removeCameraPresenceListener(androidx.camera.core.CameraPresenceListener)(listener: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraPresenceListener)`

Removes a previously registered camera presence listener.

### Inherited properties

From [androidx.camera.core.CameraProvider](https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo>` `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#availableCameraInfos()`

The `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` instances of the available cameras.

## Public companion functions

### createInstance

```
suspend fun createInstance(context: Context, cameraXConfig: CameraXConfig? = null): LifecycleCameraProvider
```

Creates a lifecycle camera provider instance.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The Application context. |
| `cameraXConfig: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig? = null` | The configuration options to configure the lifecycle camera provider. If not set, the default configuration will be used. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider` | The lifecycle camera provider instance. |

### createInstanceAsync

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

```
fun createInstanceAsync(context: Context, cameraXConfig: CameraXConfig? = null): ListenableFuture<LifecycleCameraProvider>
```

Creates a lifecycle camera provider instance asynchronously.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The Application context. |
| `cameraXConfig: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig? = null` | The configuration options to configure the lifecycle camera provider. If not set, the default configuration will be used. |

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider>` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` that will be completed when the lifecycle camera provider instance is initialized. |

## Public functions

### bindToLifecycle

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

```
fun bindToLifecycle(
    singleCameraConfigs: List<ConcurrentCamera.SingleCameraConfig?>
): ConcurrentCamera
```

Binds list of `https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera.SingleCameraConfig`s to `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`.

This function only supports combinations that are available via `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#availableConcurrentCameraInfos()`. If the input list of `https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera.SingleCameraConfig`s does not match any of the supported combinations returned by `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#availableConcurrentCameraInfos()`, `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` will be thrown. If cameras are already used by other `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`s, `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` will be thrown.

To set up concurrent camera, call `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#availableConcurrentCameraInfos()` to get the list of available combinations of concurrent cameras. Each sub-list contains the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo`s for a combination of cameras that can be operated concurrently. Each camera can have its own `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`s and `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`. See {@docRoot}training/camerax/architecture#lifecycles

There are two modes:

1. Non-Composition mode: These `https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera.SingleCameraConfig`s have different preview and video capture use cases and there is no `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings`. In this mode, these previews and video captures can stream separately. CameraX doesn't perform any composition. You can also bind an extra image capture along with the preview and the video capture use cases.

2. Composition mode: If the concurrent cameras are binding the same instances of preview and video capture use cases, the concurrent cameras video recording is supported. The concurrent camera preview stream will be shared with video capture and record the concurrent cameras streams as a composited stream. The `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings` can be used to configure the position of each camera stream and different layouts can be built. See `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings` for more details. The composition settings can also be updated dynamically by invoking `https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera#setCompositionSettings(java.util.List<androidx.camera.core.CompositionSettings>)`. The composition mode only supports preview and video capture. ImageCapture is currently not supported. `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect` can be applied on the composited stream. However, the mirrorMode of VideoCapture will be ignored. This means the recorded video will have the same mirrorMode as the preview.

| Parameters |
|---|---|
| `singleCameraConfigs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera.SingleCameraConfig?>` | Input list of `https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera.SingleCameraConfig`s. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera` | Output `https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera` instance. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If the camera configs do not match any supported concurrent camera combination in `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#availableConcurrentCameraInfos()`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` | If device is not supporting concurrent camera or cameras are already used by other `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`s. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera` |   |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#availableConcurrentCameraInfos()` |   |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo#isLogicalMultiCameraSupported()` |   |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo#getPhysicalCameraInfos()` |   |

### bindToLifecycle

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

```
fun bindToLifecycle(
    lifecycleOwner: LifecycleOwner,
    cameraSelector: CameraSelector,
    sessionConfig: SessionConfig
): Camera
```

Binds a `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` to a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`.

A `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` encapsulates the configuration required for a camera session. This includes:

- A collection of `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` instances defining the desired camera functionality.

- Session parameters to be applied to the camera.

- Common properties such as the field-of-view defined by `https://developer.android.com/reference/kotlin/androidx/camera/core/ViewPort`.

- `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect`s to be applied for image processing.

The state of the lifecycle will determine when the cameras are open, started, stopped and closed. When started, the use cases contained in the given `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` receive camera data and the parameters of `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` are used for configuring the camera including common field of view, effects and the session parameters.

Binding to a lifecycleOwner in state currently in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED` or greater will also initialize and start data capture. If the camera was already running this may cause a new initialization to occur temporarily stopping data from the camera before restarting it.

Updates the `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` for a given `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` by invoking `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,androidx.camera.core.SessionConfig)` again with the new `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig`. There is no need to call `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#unbind(kotlin.Array)` or `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#unbindAll()`; the previous `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` and its associated `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`s will be implicitly unbound. This behavior also applies when rebinding to the same `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` with a different `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector`, such as when switching the camera's lens facing.

**Important Restrictions:**

- You cannot bind a `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` to a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` that already has individual `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`s or a `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCaseGroup` bound to it.

- A `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` bound to a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` cannot contain `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`s that are already bound to a different `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`.

Violating these restrictions will result in an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html`.

The `https://developer.android.com/reference/kotlin/androidx/camera/core/Camera` returned is determined by the given camera selector, plus other internal requirements, possibly from use case configurations. The camera returned from bindToLifecycle may differ from the camera determined solely by a camera selector. If the camera selector can't resolve a valid camera under the requirements, an IllegalArgumentException will be thrown.

```kotlin
import androidx.camera.core.CameraSelector
import androidx.camera.core.ImageCapture
import androidx.camera.core.Preview
import androidx.camera.core.SessionConfig

val preview =
    Preview.Builder().build().also { it.surfaceProvider = previewView.surfaceProvider }
val imageCapture = ImageCapture.Builder().build()
val sessionConfig =
    SessionConfig(
        useCases = listOf(preview, imageCapture),
        viewPort = previewView.getViewPort(preview.getTargetRotation()),
        effects = listOf(effect1),
    )
// Starts the camera with the given effect and viewPort when the lifecycleOwner is started.
cameraProvider.bindToLifecycle(
    lifecycleOwner,
    CameraSelector.DEFAULT_BACK_CAMERA,
    sessionConfig,
)

// To apply a different effect, unbind the previous SessionConfig and bind the new SessionConfig
// with the new effect.
val sessionConfigNewEffect =
    SessionConfig(
        useCases = listOf(preview, imageCapture),
        viewPort = previewView.getViewPort(preview.getTargetRotation()),
        effects = listOf(effect2),
    )
// Make sures to unbind the previous sessionConfig before binding the new one
cameraProvider.unbind(sessionConfig)
cameraProvider.bindToLifecycle(
    lifecycleOwner,
    CameraSelector.DEFAULT_BACK_CAMERA,
    sessionConfigNewEffect,
)
```

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` | If the camera is configured in concurrent mode. For example, if a list of `https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera.SingleCameraConfig`s was bound to the lifecycle already. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if either of the following conditions is met: - A `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` or `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` is already bound to the same `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`. - A `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` contained within the `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` is already bound to a different `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`. |

### bindToLifecycle

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

```
fun bindToLifecycle(
    lifecycleOwner: LifecycleOwner,
    cameraSelector: CameraSelector,
    useCaseGroup: UseCaseGroup
): Camera
```

Binds a `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCaseGroup` to a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`.

Similar to `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,androidx.camera.core.UseCaseGroup)`, with the addition that the bound collection of `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` share parameters defined by `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCaseGroup` such as consistent camera sensor rect across all `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`s.

If one `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` is in multiple `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCaseGroup`s, it will be linked to the `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCaseGroup` in the latest `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,androidx.camera.core.UseCaseGroup)` call.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` | If the camera is configured in concurrent mode. |

### bindToLifecycle

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

```
fun bindToLifecycle(
    lifecycleOwner: LifecycleOwner,
    cameraSelector: CameraSelector,
    vararg useCases: UseCase?
): Camera
```

Binds the collection of `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` to a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`.

The state of the lifecycle will determine when the cameras are open, started, stopped and closed. When started, the use cases receive camera data.

Binding to a lifecycleOwner in state currently in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED` or greater will also initialize and start data capture. If the camera was already running this may cause a new initialization to occur temporarily stopping data from the camera before restarting it.

Multiple use cases can be bound via adding them all to a single bindToLifecycle call, or by using multiple bindToLifecycle calls. Using a single call that includes all the use cases helps to set up a camera session correctly for all uses cases, such as by allowing determination of resolutions depending on all the use cases bound being bound. If the use cases are bound separately, it will find the supported resolution with the priority depending on the binding sequence. If the use cases are bound with a single call, it will find the supported resolution with the priority in sequence of `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCapture`, `https://developer.android.com/reference/kotlin/androidx/camera/core/Preview` and then `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageAnalysis`. The resolutions that can be supported depends on the camera device hardware level that there are some default guaranteed resolutions listed in `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html#createCaptureSession(android.hardware.camera2.params.SessionConfiguration)`.

Currently up to 3 use cases may be bound to a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` at any time. Exceeding capability of target camera device will throw an IllegalArgumentException.

A UseCase should only be bound to a single lifecycle and camera selector a time. Attempting to bind a use case to a lifecycle when it is already bound to another lifecycle is an error, and the use case binding will not change. Attempting to bind the same use case to multiple camera selectors is also an error and will not change the binding.

Binding different use cases to the same lifecycle with different camera selectors that resolve to distinct cameras is an error, resulting in an exception.

The `https://developer.android.com/reference/kotlin/androidx/camera/core/Camera` returned is determined by the given camera selector, plus other internal requirements, possibly from use case configurations. The camera returned from bindToLifecycle may differ from the camera determined solely by a camera selector. If the camera selector can't resolve a valid camera under the requirements, an IllegalArgumentException will be thrown.

Only `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` bound to latest active `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` can keep alive. `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` bound to other `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` will be stopped.

| Parameters |
|---|---|
| `lifecycleOwner: https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` | The lifecycleOwner which controls the lifecycle transitions of the use cases. |
| `cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` | The camera selector which determines the camera to use for set of use cases. |
| `vararg useCases: https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase?` | The use cases to bind to a lifecycle. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/Camera` | The `https://developer.android.com/reference/kotlin/androidx/camera/core/Camera` instance which is determined by the camera selector and internal requirements. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If the use case has already been bound to another lifecycle or method is not called on main thread. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If the provided camera selector is unable to resolve a camera to be used for the given use cases. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` | If the camera is configured in concurrent mode. |

### isBound

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

```
fun isBound(sessionConfig: SessionConfig): Boolean
```

Returns `true` if the exact same instance of `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` is bound to a lifecycle, `false` otherwise.

After binding a `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig`, this `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` remains bound until the lifecycle reaches a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` state or if is unbound by calls to `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#unbind(kotlin.Array)` or `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#unbindAll()`.

### isBound

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

```
fun isBound(useCase: UseCase): Boolean
```

Returns `true` if this `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` is bound to a lifecycle or included in a bound `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig`, `false` otherwise.

After binding a use case, use cases remain bound until the lifecycle reaches a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` state or if is unbound by calls to `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#unbind(kotlin.Array)` or `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider#unbindAll()`.

### unbind

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

```
fun unbind(sessionConfig: SessionConfig): Unit
```

Unbinds the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` instance from the lifecycle provider.

This method will only unbind the session if the provided `sessionConfig` is the exact same instance that was previously used for binding.

This `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` contains the `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`s to be detached from the camera. This will initiate a close of every open camera which has zero `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` associated with it at the end of this call.

After unbinding the `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig`, another `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` can be bound again and its `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`s can be bound to another `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle`.

| Parameters |
|---|---|
| `sessionConfig: https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` | The sessionConfig that contains the collection of use cases to remove. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If not called on main thread. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` | If called in concurrent mode. |

### unbind

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

```
fun unbind(vararg useCases: UseCase?): Unit
```

Unbinds all specified use cases from the lifecycle provider.

This will initiate a close of every open camera which has zero `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` associated with it at the end of this call.

If a use case in the argument list is not bound, then it is simply ignored.

After unbinding a UseCase, the UseCase can be bound to another `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle` however listeners and settings should be reset by the application.

| Parameters |
|---|---|
| `vararg useCases: https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase?` | The collection of use cases to remove. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If not called on main thread. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` | If called in concurrent mode. |

### unbindAll

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

```
fun unbindAll(): Unit
```

Unbinds all use cases from the lifecycle provider and removes them from CameraX.

This will initiate a close of every currently open camera.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If not called on main thread. |