method called after release() exception unable to resume with android camera

后端 未结 9 602
無奈伤痛
無奈伤痛 2020-11-29 00:14

While developing a camera app I\'ve encountered an exception that only happened when I switch to other app (onPause() for my app).

01-15 17:22:1         


        
相关标签:
9条回答
  • 2020-11-29 00:57

    I faced same issue, i fixed it by - Adding mCamera = null; in surfaceDestroyed(SurfaceHolder holder) method of Preview class.

    public void surfaceDestroyed(SurfaceHolder holder) {
        // Surface will be destroyed when we return, so stop the preview.
        if (mCamera != null) {
            mCamera.stopPreview();
            mCamera.release();
            mCamera = null;
        }
    }
    

    and - Adding

    camera = Camera.open();
        camera.startPreview();
        params = camera.getParameters();
        preview.setCamera(camera);
    

    in OnResume() method of my CameraActivity.

    0 讨论(0)
  • 2020-11-29 00:57

    If you got:

    Attempt to invoke virtual method 'void android.hardware.Camera.setPreviewCallback(android.hardware.Camera$PreviewCallback)' on a null object reference

    I agree with @ookami.kb - mCamera.setPreviewCallback(null); is not enough, behind it also add this:

    mCameraView.getHolder().removeCallback(mCameraView);
    
    0 讨论(0)
  • 2020-11-29 00:58

    The docs clearly say that camera.release() releases all camera resources. After this call camera reference can not be used any more.

    If you want to use camera again you have to acquire it via a open(int) method.

    It's all described in the camera docs.

    0 讨论(0)
提交回复
热议问题