Camera error when locking / unlocking a device

I work with a camera and I use the same example provided in the documentation: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html

I am running an example in Xoom with Android 3.1 and 3.2.

My problem is that when I lock and unlock the Xoom, the camera does not return. The image remains the same as the last before I close the tablet, and the red light also does not return.

If anyone can help me, I will be grateful.

+4
source share
2 answers

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.

+8
source

One solution, perhaps, again draws attention to the invisibility and visibility of the surface in onResume (), which reduces and recreates surface vision.

0
source

Source: https://habr.com/ru/post/1368905/


All Articles