tags:

views:

23

answers:

0

I am testing the Android CameraPreview demo on a Motorola Droid running 2.1-update1.

If, while the activity is running, I press Home and then do a long press on Home to return to it, the preview image is the wrong size. Opening the physical keyboard corrects the issue - I'm guessing that a configurationChange is fired, the surface gets destroyed and then created again, then in surfaceChanged the preview gets set to the correct size.

I added logging to surfaceChanged as follows:

Log.i("[appMobi]", "surfaceChanged: raw size("+w+","+h+") optimal size("+optimalSize.width+","+optimalSize.height+")");

and this is the output after starting the activity, pressing Home, returning via a long press on Home and then sliding out the keyboard:

08-05 09:27:28.231: INFO/[test](3920): surfaceChanged: raw size(569,295) optimal size(352,288)
08-05 09:27:35.676: INFO/[test](3920): surfaceChanged: raw size(569,295) optimal size(352,288)
08-05 09:27:39.028: INFO/[test](3920): surfaceChanged: raw size(569,295) optimal size(352,288)

So in each case the previewSize is being set to the same value, but in the second case it results in a smaller actual preview image.

Since sliding the keyboard open corrects the issue, I thought it might be a timing thing, so I added a Thread that sets the previewSize and then sleeps for 500ms but that didn't affect the behavior.

Anyone have any idea why this happens and what can be done to fix it? Does it happen on other devices or is it Droid specific? Thanks!