title: How to take multiple images using CameraX?
body: <p>My use case is to take two images at one time. first one at 2x zoom and second one at 1x zoom level. Also, I want to save images to files.</p>
  
  <p>My idea of doing it was to take the first image at 2x zoom and when the image is saved set the zoom level at 1x and take the second image when the lens has zoomed to 1x zoom level.</p>
  
  <p>However, when I take the first image the preview is stuck at the first image and callback from setting 1x zoom never happens.</p>
  
  <p>This is how I create the capture use cases.</p>
  
  <pre><code>private void createImageCaptureUseCases() {
      ImageCapture imageCapture1 = new ImageCapture.Builder()
          .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
          .build();
  
      ImageCapture imageCapture2 = new ImageCapture.Builder()
          .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
          .build();
  
      imageCaptureUseCases.clear();
      imageCaptureUseCases.add(imageCapture1);
      imageCaptureUseCases.add(imageCapture2);
  </code></pre>
  
  <p>This is how I first start the camera session.</p>
  
  <pre><code>ListenableFuture&lt;ProcessCameraProvider&gt; cameraProviderFuture = ProcessCameraProvider.getInstance(getContext());
  
  cameraProviderFuture.addListener(() -&gt; {
      try {
          cameraProvider = cameraProviderFuture.get();
          preview = new Preview.Builder().build();
  
          cameraSelector = new CameraSelector.Builder()
              .requireLensFacing(CameraSelector.LENS_FACING_BACK)
              .build();
  
          Camera camera = cameraProvider.bindToLifecycle(
              ((LifecycleOwner) this),
              cameraSelector,
              preview,
              imageCapture);
  
          camera.getCameraControl().setZoomRatio(2f);
  
          preview.setSurfaceProvider(previewView.createSurfaceProvider(camera.getCameraInfo()));
      } catch (InterruptedException | ExecutionException e) {}
  }, ContextCompat.getMainExecutor(getContext()));
  </code></pre>
  
  <p>this is how the capture images is called.</p>
  
  <pre><code>private void captureImage(ImageCapture imageCapture) {
  
      File pictureFile = ImageUtils.createImageFile(getActivity());
      ImageCapture.OutputFileOptions options = new 
          ImageCapture.OutputFileOptions.Builder(pictureFile).build();
  
      final Activity activity = getActivity();
  
      imageCapture.takePicture(options, ContextCompat.getMainExecutor(activity),
          new ImageCapture.OnImageSavedCallback() {
  
              @Override
              public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults){
                  Log.i("my tag", "image Saved: " + pictureFile.getAbsolutePath());
  
                  int index = imageCaptureUseCases.indexOf(imageCapture);
                  cameraProvider.unbind(imageCapture);
                  if (index &lt; imageCaptureUseCases.size() - 1) {
                      Camera camera = cameraProvider.bindToLifecycle(
                      (LifecycleOwner) activity,
                      cameraSelector,
                      imageCaptureUseCases.get(index + 1));
  
                      ListenableFuture future = camera.getCameraControl().setZoomRatio(1f);
                      future.addListener(() -&gt; captureImage(imageCaptureUseCases.get(index + 1)),
                                      ContextCompat.getMainExecutor(activity));
                  } else {
                      createImageCaptureUseCases();
                      cameraProvider.unbindAll();
                      Camera camera = cameraProvider.bindToLifecycle(
                          (LifecycleOwner) activity,
                          cameraSelector,
                          preview,
                          imageCaptureUseCases.get(0));
  
                      camera.getCameraControl().setZoomRatio(2f);
                  }
              }
  
              @Override
              public void onError(@NonNull ImageCaptureException exception) {
                  Log.i("my tag", "image save error: " + pictureFile.getAbsolutePath());
              }
      });
  }
  </code></pre>