Lock and unlock, do you mean when the screen is sleeping or the power switch of the device is pressed so that the device falls asleep and then wakes up?
If so, I suspect that you need to free the camera resources in your onPause, and then run the preview again on onResume, turning to the callback.
In Android 2.2 and 2.3 applications, I have this camera deal I am using:
onCreate: - get reference to the camera onResume: - sv = (SurfaceView)this.findViewById(R.id.capture_SurfaceView); mHolder = sv.getHolder(); mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); mHolder.setSizeFromLayout(); mHolder.addCallback(this); surfaceChanged: - Camera.setPreviewDisplayHolder() - Camera.startPreview() onPause: - Camera.stopPreview - SurfaceHolder.removeCallback() - Camera.release()
This works well for me through a device that turns off and then turns back on, or my application otherwise goes into the background.
source share