Android Camera相机 Camera is being used after Camera.release() was called

camera在切换前后摄像头时的异常

    Process: com.test.wrapper, PID: 8923
    java.lang.RuntimeException: Camera is being used after Camera.release() was called
        at android.hardware.Camera.setHasPreviewCallback(Native Method)
        at android.hardware.Camera.-wrap1(Unknown Source:0)
        at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1237)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:173)
        at android.app.ActivityThread.main(ActivityThread.java:6698)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
原因:

缺少mCamera?.setPreviewCallback(null)
果然调试代码时候还是要小心翼翼点儿啊...

       mCamera?.stopPreview()
       mCamera?.setPreviewDisplay(null)
       mCamera?.setPreviewCallback(null)
       mCamera?.lock()
       mCamera?.release()
       mCamera = null

你可能感兴趣的:(Android Camera相机 Camera is being used after Camera.release() was called)