I had the same problem and this is why:
The onPause method does not recycle the CameraPreview class that I made (which implements SurfaceView callbacks). Instead of trying to recreate an instance of this entire object, I just updated the link to the camera object that I passed in order to be either
null
or
cameraPreview.setCamera(mCamera);
I called the getCameraInstance method to initialize the camera, and then passed it to the preivew object.
Now the problem is here:
private void initializeCameraView(){ RelativeLayout preview = (RelativeLayout)rootView.findViewById(R.id.camera_preview); preview.addView(cameraPreview); }
in onResume, I called this method to initialize the cameraPreview object. However, it hung because I was trying to add another kind of camera to the preview view . It was my fix, simple and simple. If it already exists, delete it and then return it. Hope this helps!
private void initializeCameraView(){ RelativeLayout preview = (RelativeLayout)rootView.findViewById(R.id.camera_preview);
Nlinscott
source share