Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera example bug when locking/unlocking device

I'm working with the camera and I'm using the exact same example given in the documentation : http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html

I running the example on a Xoom with Android 3.1 and 3.2.

My problem is when I lock and unlock the Xoom, the camera doesn't come back. The image stay the same as the last one before I locked the tablet and the red light doesn't come back either.

If anyone could help me, I will appreciate.

like image 981
darkzangel Avatar asked Feb 23 '23 04:02

darkzangel


1 Answers

By lock and unlock, do you mean when the screen sleeps or the device power switch is pressed putting the device to sleep and then woken back up?

If so, I suspect you need to release the camera resources in your onPause and then start the preview again in onResume, via the surface view callback.

In the Android 2.2 and 2.3 apps I have that deal with camera the pattern I use is:

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 across the device getting turned off and then back on, or my app otherwise going to background.

like image 112
mmeyer Avatar answered Mar 07 '23 20:03

mmeyer