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

后端 未结 9 659
無奈伤痛
無奈伤痛 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:55

    Adding to okambi's answer.

    This is the function messing everything up when you resume:

     public void surfaceCreated(SurfaceHolder holder) {
            // The Surface has been created, now tell the camera where to draw the preview.
            try {
                mCamera.setPreviewDisplay(holder);
                mCamera.startPreview();
            } catch (IOException e) {
                Log.d(TAG, "Error setting camera preview: " + e.getMessage());
            }
        }
    

    The try{} is not catching the exception being thrown. Namely that mCamera doesn't exist, and then when it tries to call setPreviewDisplay(holder), there is a crash.

    So by removing the callback, this surfaceCreated doesn't get called and avoids the crash.

    This is VERY POORLY DOCUMENTED by Google.

提交回复
热议问题