When using firebase ml vision to recognize qr codes and/or text from an image. What is the best way to wait for the async text and barcode detector methods to resolve so I can utilize their results in a third method.
I am aware than I can call an alternative method from each async methods "onsuccess" listener to set a "hasReturned" variable and only proceed once both methods have returned but I am looking for the proper way to do this.
private void firebaseRecognitionFromImage(FirebaseVisionImage image) {
//detect qr code
FirebaseVisionBarcodeDetectorOptions options = new FirebaseVisionBarcodeDetectorOptions.Builder().setBarcodeFormats(FirebaseVisionBarcode.FORMAT_ALL_FORMATS).build();
FirebaseVisionBarcodeDetector qrDetector = FirebaseVision.getInstance().getVisionBarcodeDetector(options);
qrDetector.detectInImage(image).addOnSuccessListener(new OnSuccessListener<List<FirebaseVisionBarcode>>() {
@Override
public void onSuccess(List<FirebaseVisionBarcode> barcodes) { /* RESULT 1 */ }
});
//detect text
FirebaseVisionTextRecognizer textDetector = FirebaseVision.getInstance().getOnDeviceTextRecognizer();
textDetector.processImage(image).addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
@Override
public void onSuccess(FirebaseVisionText texts) { /* RESULT 2 */ }
});
//process qr code and text information or lack thereof
thirdMedthod("RESULT 1", "RESULT 2");
}