'CameraX freeze photo capture (frequently)

I am facing a similar problem (CameraX video recording freezes and generates empty video file) for capturing photo. I am trying to take multiple photos using our app. Preview and taking the first photo is always fine. But when I try to take a second or third photo, camera stops taking photos. Log is attached here. Thanks in advance.

imageCapture.takePicture(image, ContextCompat.getMainExecutor(this),
                new ImageCapture.OnImageSavedCallback() {
                    @Override
                    public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
                        runOnUiThread(() -> {
                            onPictureTakenOption(photoFilePath);
                        });
                    }
                    @Override
                    public void onError(@NonNull ImageCaptureException exception) {

                    }
                }
        );


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source