private Executor executor = Executors.newSingleThreadExecutor();
captureImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imageCapture.takePicture(executor, new ImageCapture.OnImageCapturedCallback() {
@SuppressLint("UnsafeExperimentalUsageError")
@Override
public void onCaptureSuccess(@NonNull ImageProxy image) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
cameraProvider.unbind(preview);
}
});
FragmentCroppImage fragment2 = new FragmentCroppImage();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.addToBackStack(null);
fragmentTransaction.replace(R.id.frameLHaupt, fragment2);
fragmentTransaction.commit();
}
@Override
public void onError(@NonNull ImageCaptureException exception) {
exception.printStackTrace();
}
});
}
});
我有一个简单的代码。当我拍照后,我打开新的片段(fragment)。没有问题,但是当我返回到相机(cameraX)片段(popbackstack)时,会收到以下错误:
Attempting to bind too many ImageCapture or VideoCapture instances
。经过研究后,我读到了下面的答案:答案链接。我需要解绑(unbind)相机(CameraX)组件,而我确实这样做了,但仍然出现同样的错误。
所以现在我卡住了。可能是什么原因呢? 看起来似乎我需要在imagecapture之前就解绑(bind)元素?