title: Issue with the android camera and thread safety
body: <p>As pointed out in the <a href="http://developer.android.com/training/camera/cameradirect.html#TaskOpenCamera">Android documentation on handling the camera</a>, it is recommended to use a separate thread to open the camera.</p>
  
  <p>Well, I am doing just that but do have some difficulties:</p>
  
  <p>For my camera object I am using a global instance variable. Now, when I start my app, I create a separate thread in <code>onResume()</code> and do all initializations for that camera object in that thread.</p>
  
  <p>Later when I leave the app, I release the camera in <code>onPause()</code>. This works all just fine.</p>
  
  <p><strong>But the problem is</strong>: When I did some stress tests and switched really fast  between <code>onResume()</code> and <code>onPause()</code> (by hitting the multitask button excessively fast) my app crashed. The reason was that there was a <code>Method called after release()</code>.</p>
  
  <p>This makes sense since it is possible that the camera may be released in <code>onPause()</code> but at the same time the thread hasn't finished with its initialization. Thus, the thread tries to make a call on a camera object that was already released.</p>
  
  <p>Now, what can I do to fix this? Maybe not use a global camera object? Or how can I make this thread safe?</p>