I have a function (not inside an activity) which uploads an image to firebase storage and returns the url.
My problem is, I need to wait for the **UploadTask** to finish or else it returns me a null string. .

```
 public String pushRegisterImage(Bitmap image) {
    StorageReference imagesRef = storage.getReferenceFromUrl(STORAGE_REF)
            .child(FINDMYPET).child(IMAGES).child(String.valueOf(UUID.randomUUID()));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] data = baos.toByteArray();
    UploadTask uploadTask = imagesRef.putBytes(data);

    uploadTask.addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            imageUrl = null;
            Log.e(LOG_TAG, "Image upload error: " + e);
        }
    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            imageUrl = taskSnapshot.getDownloadUrl().toString();
            Log.v(LOG_TAG, "Image uploade sucess, url: " + imageUrl);
        }
    });
    return imageUrl;
}

```