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
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.