title: Failed to create capture session; configuration failed : after recording many clips
body: <p>I've developed an app using camera2 API. Mainly the application will record the video and while recording, according to given time it will save that video clip in internal storage and the clip name will save in SQLite db and the capturing process will continue.</p>
  
  <p>Problem is: After 3 or 4 clips saving the application will stop without giving a proper error. I've searched about this <a href="https://stackoverflow.com/questions/37060114/error-failed-to-create-capture-session">link 1</a>, <a href="https://stackoverflow.com/questions/44650843/android-camera2-configure-crashes-without-reporting-proper-error">link 2</a>, <a href="https://stackoverflow.com/questions/31073892/cant-configure-camera2-api-for-a-preview">link 3</a> and also <a href="https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.StateCallback.html" rel="nofollow noreferrer">Android developers</a>. And the <a href="https://github.com/commonsguy" rel="nofollow noreferrer">commonsguy</a> has implement CAMERA API and there is also the same issue. But he has solved it and I couldn't figure it out what exactly he did. And also <a href="https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.StateCallback.html" rel="nofollow noreferrer">Android developers</a> didn't mention about any kind of this matters. Those SO questions also haven't quite answered regarding this.</p>
  
  <p>Here the Log:</p>
  
  <pre><code>    Session 9: Failed to create capture session; configuration failed
  09-21 12:24:19.873 8353-8353/com.android.ejsoft.video_upload_000web W/System.err: android.hardware.camera2.CameraAccessException: Illegal state encountered in camera service.
  09-21 12:24:19.873 8353-8353/com.android.ejsoft.video_upload_000web W/System.err:     at android.hardware.camera2.utils.CameraBinderDecorator.throwOnError(CameraBinderDecorator.java:131)
  09-21 12:24:19.873 8353-8353/com.android.ejsoft.video_upload_000web W/System.err:     at android.hardware.camera2.utils.CameraBinderDecorator$CameraBinderDecoratorListener.onAfterInvocation(CameraBinderDecorator.java:73)
  09-21 12:24:19.873 8353-8353/com.android.ejsoft.video_upload_000web W/System.err:     at android.hardware.camera2.utils.Decorator.invoke(Decorator.java:81)
  09-21 12:24:19.873 8353-8353/com.android.ejsoft.video_upload_000web W/System.err:     at java.lang.reflect.Proxy.invoke(Proxy.java:397)
  09-21 12:24:19.873 8353-8353/com.android.ejsoft.video_upload_000web W/System.err:     at $Proxy1.endConfigure(Unknown Source)
  09-21 12:24:19.873 8353-8353/com.android.ejsoft.video_upload_000web W/System.err:     at android.hardware.camera2.impl.CameraDeviceImpl.configureOutputsChecked(CameraDeviceImpl.java:383)
  09-21 12:24:19.873 8353-8353/com.android.ejsoft.video_upload_000web W/System.err:     at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSession(CameraDeviceImpl.java:437)
  09-21 12:24:19.883 8353-8353/com.android.ejsoft.video_upload_000web W/System.err:     at com.android.ejsoft.video_upload_000web.Cam2VideoFrag.startRecordingVideo(Cam2VideoFrag.java:530)
  09-21 12:24:19.883 8353-8353/com.android.ejsoft.video_upload_000web W/System.err:     at com.android.ejsoft.video_upload_000web.Cam2VideoFrag.access$1300(Cam2VideoFrag.java:60)
  09-21 12:24:19.883 8353-8353/com.android.ejsoft.video_upload_000web W/System.err:     at com.android.ejsoft.video_upload_000web.Cam2VideoFrag$4$2.onInfo(Cam2VideoFrag.java:556)
  09-21 12:24:19.883 8353-8353/com.android.ejsoft.video_upload_000web W/System.err:     at android.media.MediaRecorder$EventHandler.handleMessage(MediaRecorder.java:1159)
  09-21 12:24:19.883 8353-8353/com.android.ejsoft.video_upload_000web W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
  </code></pre>
  
  <p>The error is directly focused on:</p>
  
  <pre><code>mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {
  </code></pre>
  
  <p>Some time maybe is too many calls for the restart  <code>createCaptureSession</code> class. This only my suggestion. How can I resolve this?</p>
  
  <p><b>Thank you for your valuable time..!</b></p>