react-native-barcodescanner: Camera shows black viewfinder after device has been in "sleep mode" or "screen timeout"

Hi,

The camera doesn’t wake up / work after the device has been in sleep mode or the screen was in screen timeout mode.

Test Device

  • Samsung Galaxy Tab6a
  • Android 5.1.1

How to replicate the issue:

  1. Open app that uses the react-native-barcodescanner and go to the view that uses the camera
  2. Navigate away from the view to any view that doesn’t use the camera
  3. Let the device go to sleep or in screen timeout mode
  4. Unlock screen and go to view which uses the camera

In all of my apps the viewfinder is black after walking through the previous steps

What I found so far:

  • It is not a permission issue
  • If I close the app after this issue has occured and reopen it the camera does work again
  • If I leave the view with the camera open and let the device go to sleep, it will work after I unlock the screen
  • When this issue occurs the android camera app also doesn’t work
  • The Android device monitor shows the following errors when the device goes to sleep:

09-01 22:56:55.833: E/CameraPreview(15121): java.lang.RuntimeException: Camera is being used after Camera.release() was called 09-01 22:56:55.833: E/CameraPreview(15121): java.lang.RuntimeException: Camera is being used after Camera.release() was called 09-01 22:56:55.833: E/CameraPreview(15121): at android.hardware.Camera.native_cancelAutoFocus(Native Method) 09-01 22:56:55.833: E/CameraPreview(15121): at android.hardware.Camera.cancelAutoFocus(Camera.java:1348) 09-01 22:56:55.833: E/CameraPreview(15121): at com.eguma.barcodescanner.CameraPreview.stopCameraPreview(CameraPreview.java:89) 09-01 22:56:55.833: E/CameraPreview(15121): at com.eguma.barcodescanner.CameraPreview.stopCamera(CameraPreview.java:52) 09-01 22:56:55.833: E/CameraPreview(15121): at com.eguma.barcodescanner.BarcodeScannerView.onPause(BarcodeScannerView.java:43) 09-01 22:56:55.833: E/CameraPreview(15121): at com.eguma.barcodescanner.BarcodeScannerManager.onHostPause(BarcodeScannerManager.java:58) 09-01 22:56:55.833: E/CameraPreview(15121): at com.facebook.react.bridge.ReactContext.onHostPause(ReactContext.java:179) 09-01 22:56:55.833: E/CameraPreview(15121): at com.facebook.react.XReactInstanceManagerImpl.moveToBeforeResumeLifecycleState(XReactInstanceManagerImpl.java:573) 09-01 22:56:55.833: E/CameraPreview(15121): at com.facebook.react.XReactInstanceManagerImpl.onHostPause(XReactInstanceManagerImpl.java:489) 09-01 22:56:55.833: E/CameraPreview(15121): at com.facebook.react.ReactActivity.onPause(ReactActivity.java:120) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.Activity.performPause(Activity.java:6765) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1338) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:4418) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:4391) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:4366) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.access$1200(ActivityThread.java:219) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1746) 09-01 22:56:55.833: E/CameraPreview(15121): at android.os.Handler.dispatchMessage(Handler.java:102) 09-01 22:56:55.833: E/CameraPreview(15121): at android.os.Looper.loop(Looper.java:145) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.main(ActivityThread.java:6939) 09-01 22:56:55.833: E/CameraPreview(15121): at java.lang.reflect.Method.invoke(Native Method) 09-01 22:56:55.833: E/CameraPreview(15121): at java.lang.reflect.Method.invoke(Method.java:372) 09-01 22:56:55.833: E/CameraPreview(15121): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 09-01 22:56:55.833: E/CameraPreview(15121): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

Please help! I really need this to work.

Thanks.

Regards, Gawein

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 5
  • Comments: 19

Most upvoted comments

I experienced this issue on my Meizu MX5, fixed it by making CameraManager a singleton. Please check whether pr #61 solved your problem @bo4a10

Hi @getreup ! making mCamera static didn’t help me. if you have any other ideas - please post them. thanks in advance! Android 4.4.2 RN 0.34.1 Scanner 3.1.1

Hi!

I have fixed this and made a pr here: https://github.com/ideacreation/react-native-barcodescanner/pull/59

The issue is that this library does not handle multiple camera instances properly, and react’s handling of the module instances shouldn’t really be depended on. So, all I did was make the camera static.