I am developing an app that uses the camera. I have made the preview class like this:
public class MyPreview extends SurfaceView implements SurfaceHolder.Callback, Camera.Preview Callback{
...
public void surfaceCreated(SurfaceHolder holder){
...
mCamera.setPreviewCallback(this);
...
}
public void surfaceDestroyed(SurfaceHolder holder){
...
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h){
...
}
public void onPreviewFrame(byte[] data, Camera camera){
...
}
}
Basically, it is the CameraDemo example. Android CameraDemo Example
The problem is, surfaceCreated is called just once (the way it should), but surfaceChanged is being constantly called (instead of just once, or when the surface changes), and I believe this is the reason why onPreviewFrame is never called. The camera feed is shown on the screen and it seems to be working fine, but it really is not.
The funny thing is that it works fine on Android 2.x, and the issues only arise on Android 4.1. (I have not tested it on other devices)
I have been looking around and I believe it may be the real reason behind this stackoverflow unsolved question and this another stackoverflow unsolved question and this code.google case. This last case has a "solution", but it did not work for me.
So, any ideas to why surfaceChanged is being entered all the time and how to solve it?