diff --git a/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt b/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt index a557016061..f7ef066bbd 100644 --- a/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt +++ b/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt @@ -84,6 +84,7 @@ class CameraSession(internal val context: Context, internal val callback: Callba override fun close() { Log.i(TAG, "Closing CameraSession...") isDestroyed = true + orientationManager.clearListeners() runOnUiThread { lifecycleRegistry.currentState = Lifecycle.State.DESTROYED } diff --git a/package/android/src/main/java/com/mrousavy/camera/core/OrientationManager.kt b/package/android/src/main/java/com/mrousavy/camera/core/OrientationManager.kt index 4254452b61..44efb58a54 100644 --- a/package/android/src/main/java/com/mrousavy/camera/core/OrientationManager.kt +++ b/package/android/src/main/java/com/mrousavy/camera/core/OrientationManager.kt @@ -67,13 +67,17 @@ class OrientationManager(private val context: Context, private val callback: Cal } } + // remove previous listeners if attached + func clearListeners() { + displayManager.unregisterDisplayListener(displayListener) + orientationListener.disable() + } + fun setTargetOutputOrientation(targetOrientation: OutputOrientation) { Log.i(TAG, "Target Orientation changed $targetOutputOrientation -> $targetOrientation!") targetOutputOrientation = targetOrientation - // remove previous listeners if attached - displayManager.unregisterDisplayListener(displayListener) - orientationListener.disable() + clearListeners() when (targetOrientation) { OutputOrientation.DEVICE -> {