Camera Preview after coming from background
<p>I am implementing an application where I can run the camera in background and in foreground 
without stopping it. When I display the preview after coming from background I get a persistent distorted image.
Do I need to do anything special for recreating the preview?</p>

<p>Thanks, Reea</p>

<p>This is my code:</p>

<pre><code>@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    //get the Surface View at the main.xml file
    sv = (SurfaceView) findViewById(R.id.surfaceView);

    //Get a surface
    sHolder = sv.getHolder();

    //add the callback interface methods defined below as the Surface View callbacks
    sHolder.addCallback(this);

    //tells Android that this surface will have its data constantly replaced
}

@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) 
{
     //get camera parameters
     parameters = mCamera.getParameters();
     parameters.setPreviewFormat(ImageFormat.NV21);

     //set camera parameters
     mCamera.setParameters(parameters);
     mCamera.startPreview();

}

@Override
public void surfaceCreated(SurfaceHolder holder) 
{
    // The Surface has been created, acquire the camera and tell it where
    // to draw the preview.
    mCamera = Camera.open();
    try {
       mCamera.setPreviewDisplay(holder);

    } catch (IOException exception) {
        mCamera.release();
        mCamera = null;
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) 
{
    //stop the preview
    //mCamera.stopPreview();
    //release the camera
            //mCamera.release();
            //unbind the camera from this object
            //mCamera = null;

    }  
</code></pre>
