title: How to thread camera callbacks in Android?
body: <p>I'm writing an Android app that obtains continuous updates from the camera and processes them whenever onPreviewFrame(byte[] data, Camera camera) is called.</p>
  
  <p>The problem is that onPreviewFrame is only getting called around 8-10 times per second, as opposed to 30 times (which I expected for a 30 FPS camera). I think it's because my UI is receiving all of the camera callbacks as opposed to a separate thread.</p>
  
  <p>Here is my SurfaceView that holds the camera and receives camera callbacks:</p>
  
  <pre><code>public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback, Callback {
  private Camera mCamera;
  ...
  mCamera.setPreviewCallback(new Camera.PreviewCallback() {
                  @Override
                  public void onPreviewFrame(byte[] data, Camera camera) {
                      //Frame received (about 8 per second)
  </code></pre>
  
  <p>And here is the code where I open the camera (in my main activity):</p>
  
  <pre><code>final Camera camera = getCameraInstance();    //calls camera.open()
  
  mPreview = new CameraPreview(this, camera);
  </code></pre>
  
  <p>How should I go about using a thread, Asynctask, or Handler to make the camera callbacks happen on the side? And how would I receive these updates in the UI thread?</p>