title: android camera surfaceview orientation
body: <p>Ok so I have a class that extends SurfaceView and overrides  </p>
  
  <p>surfaceChanged - just calls startPreview<br>
  surfaceCreated - opens camera, edits params *, sets surfaceHolder<br>
  surfaceDestroyed - calls stopPreview, release camera  </p>
  
  <p>this all work great because when the orientation is Portrait:  </p>
  
  <p>from surfaceCreated *</p>
  
  <pre><code>m_camera = Camera.open();
  Camera.Parameters p = m_camera.getParameters();
  
  if (getResources().getConfiguration().orientation != 
      Configuration.ORIENTATION_LANDSCAPE)
  {
      p.set("orientation", "portrait");
  
      // CameraApi is a wrapper to check for backwards compatibility  
      if (CameraApi.isSetRotationSupported())
      {
           CameraApi.setRotation(p, 90);
      }
  }
  </code></pre>
  
  <p>However, everytime the orientation changes it calls Camera.open()... which as you may know is quite an expensive operation, causing the transitions to be not so smooth.</p>
  
  <p>When i force the orientation to landscape, the preview is great. Create only gets called once which works because the preview is in landscape the camera is always what the user sees. However, I need a way to set the orientation of the actual picture taken when in portrait. When I force landscape though, the surface never gets recreated and the parameters are never set when the camera is held in portrait.</p>
  
  <p>So how can I do one of the following (exclusively)?  </p>
  
  <ol>
  <li><p><strong>Hold onto m_camera</strong> between onDestroy and onCreate when orientation changes so that the transition is smooth</p></li>
  <li><p><strong>Force landscape</strong> and detect orientation changes another way... rotating the final snaped picture if held in portrait.</p></li>
  </ol>
  
  <p>Also, if I am off base can someone point me in a better direction? Thank you.</p>