title: Android Camera.takePicture() does not return some times?
body: <p>I am writing an application for android to take pictures. The code does some processing after getting a frame from preview in onPreviewFrame(byte[] data, Camera camera).
  The problem is with function takePicture() of android.hardware.Camera that sometimes do exactly what I want and sometimes does not return and no callbacks will be called. When I run the app some times taking the first picture does not return and some times I can take four pictures and the fifth will cause app to hang. There is a simillar thread: <a href="https://stackoverflow.com/questions/7258473/problem-with-taking-pictures-using-the-android-camera">problem with taking pictures using the android camera</a>. The suggested solution is to use the frame from last preview but surely it is not a good solution! This problem may raise because takePicture is Asancronous (<a href="http://developer.android.com/reference/android/hardware/Camera.html#takePicture%28android.hardware.Camera.ShutterCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback%29" rel="nofollow noreferrer">Android Doc</a>).</p>
  
  <p>I simply call the takePicture() function like this:</p>
  
  <pre><code>public static void takePicture() {
     mCamera.takePicture(null, null, jpegCallback);
  }
  </code></pre>
  
  <p><a href="http://www.mediafire.com/?e4b3wucgg2rf1xp" rel="nofollow noreferrer">Here</a> is the link to Logcat output. You can search in the output with phrase "takePicture" and you will see that this function sometimes return and sometimes does not return. </p>
  
  <p>This is the output for when takePicture return:</p>
  
  <pre><code>10-02 19:24:36.570: INFO/ShotSingle(3198): ShotSingle::takePicture start
  10-02 19:24:36.570: DEBUG/CameraHal(3198): 2489: takePicture() ENTER
  10-02 19:24:36.570: DEBUG/MessageQueue(3198): MQ.put(5,0xb6590,0x0,0x8,0x80b0af55)
  10-02 19:24:36.570: DEBUG/MessageQueue(3198): MessageQueue::put EXIT
  10-02 19:24:36.578: DEBUG/MessageQueue(3198): MQ.get(5,0xb6590,0x0,0x8,0x80b0af55)
  10-02 19:24:36.578: DEBUG/CameraHal(3198): 1458: CameraStop() ENTER
  10-02 19:24:36.617: DEBUG/CameraHal(3198): 1543: CameraStop() EXIT
  10-02 19:24:36.617: DEBUG/MessageQueue(3198): MQ.put(14,0xb6590,0x0,0x8,0x80b0af55)
  10-02 19:24:36.617: DEBUG/MessageQueue(3198): MQ.get(14,0xb6590,0x0,0x8,0x80b0af55)
  10-02 19:24:36.617: DEBUG/CameraHal(3198): 2497: takePicture() EXIT
  10-02 19:24:36.617: INFO/ShotSingle(3198): ShotSingle::takePicture end
  </code></pre>
  
  <p>and this is the output for when takePicture does not return:</p>
  
  <pre><code>10-02 19:25:20.671: INFO/ShotSingle(3198): ShotSingle::takePicture start
  10-02 19:25:20.671: DEBUG/CameraHal(3198): 2489: takePicture() ENTER
  10-02 19:25:20.671: DEBUG/MessageQueue(3198): MQ.put(5,0xb8cb8,0x0,0x8,0x80b0af55)
  10-02 19:25:20.671: DEBUG/MessageQueue(3198): MessageQueue::put EXIT
  10-02 19:25:21.343: INFO/StatusBarPolicy(3393): onSignalStrengthsChanged
  10-02 19:25:22.609: WARN/PowerManagerService(3330): Timer 0x7-&gt;0x3|0x7
  10-02 19:25:23.062: INFO/AudioStreamOutALSA(3198): (virtual android::status_t android::AudioStreamOutALSA::standby())  enter
  10-02 19:25:23.125: ERROR/AudioStreamOutALSA(3198): Output standby called!!. Turn off PCM device.
  10-02 19:25:23.125: INFO/ALSAStreamOps(3198): [ALSAStreamOps]codecOff mode = 0
  10-02 19:25:23.234: INFO/AudioStreamOutALSA(3198): [AudioOutLock]Relase_wake_Lock 
  </code></pre>
  
  <p>Does anyone have any explanation or solution for this problem?</p>