I see some problems with your AutoFocus processing code.
Analysis result
There is a loop in your autofocus.
Explanation
a) The camera preview class mAutoFocusCallback set using autoFocusCb Camera Activity .
public CameraPreviewNew(Context context,...,AutoFocusCallback autoFocusCb) { super(context); mAutoFocusCallback = autoFocusCb; ... }
b) surfaceChanged is called once during activity loading. The camera requires autofocus.
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { if (mCamera != null) { ... mCamera.startPreview(); mCamera.autoFocus(mAutoFocusCallback); ... } }
c) Upon completion of autofocus, the mAutoFocusCallback callback is called. mAutoFocusCallback->autoFocusCb->onAutoFocus()
Camera activity
Camera.AutoFocusCallback autoFocusCB = new Camera.AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { mAutoFocusHandler.postDelayed(doAutoFocus, 1000); } };
d) onAutoFocus assigns another autofocus after 1000 milliseconds, 1 second.
Camera activity
public void onAutoFocus(boolean success, Camera camera) { mAutoFocusHandler.postDelayed(doAutoFocus, 1000); }
e) After one second, messages are sent to the handler, which calls the current doAutoFocus requesting camera for auto focus , similar to b) above.
private Runnable doAutoFocus = new Runnable() { public void run() { if (mCamera != null && mPreviewing) { mCamera.autoFocus(autoFocusCB); } } };
f) After autofocus is autoFocusCb , autoFocusCb similar to c) is called again . and the cycle continues.
Camera.AutoFocusCallback autoFocusCB = new Camera.AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { mAutoFocusHandler.postDelayed(doAutoFocus, 1000); } };
Decision
I am confused why such an implementation. This cycle may cause you to not listen to the flash on / off calls. You need to remove the code below and do something meaningful, otherwise leave onAutoFocus () empty.
Camera.AutoFocusCallback autoFocusCB = new Camera.AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { mAutoFocusHandler.postDelayed(doAutoFocus, 1000); } };
To automatically focus with each movement of the camera, you need to use the motion sensors that came with the phone. You can google it
Hope this helps. Happy coding ...