6

I have a camera app that allows the user to take pictures. On my main screen I have a camera rendered on a SurfaceView. When the user takes a photo, I call camera.autoFocus and on the AutoFocusCallback callback I call camera.takePicture. Then I save the photo and go to another activity to preview the photo. I call camera.stopPreview() when leaving the camera page (onPause), and camera.startPreview() when coming back (onResume).

The camera is initialized using FOCUS_MODE_CONTINUOUS_PICTURE. I do not recycle the camera when coming back to the camera page (since it is a slow operation that takes ~2 seconds), but just call startPreview if the camera has been initialized before.

Here is my problem. Before taking the first photo, continuous autofocus works fine since FOCUS_MODE_CONTINUOUS_PICTURE is set up initially on the camera. However after calling camera.autoFocus, FOCUS_MODE_CONTINUOUS_PICTURE stops working. Later when I return to the same screen and call startPreview, continuous auto focus does not work kick in anymore.

Is there a way to restart continuous autofocus without having to restart the camera? I'd like to avoid restarting the camera as this causes several seconds of delay for the user.

mliu
  • 1,708
  • 15
  • 26

1 Answers1

17

I fixed the issue by calling camera.cancelAutoFocus(). This caused continuous autofocus to kick in again.

mliu
  • 1,708
  • 15
  • 26
  • 2
    If applications want to resume the continuous focus, cancelAutoFocus must be called. Restarting the preview will not resume the continuous autofocus. http://developer.android.com/reference/android/hardware/Camera.Parameters.html#FOCUS_MODE_CONTINUOUS_PICTURE – Elyess Abouda Oct 23 '14 at 08:59