【发布时间】:2022-01-07 23:43:33
【问题描述】:
所以我正在使用 for 循环将多个图像上传到 firebase 存储,现在我想在所有图像上传后关闭 Activity
我尝试使用finish(); 但因为它是一个循环,所以会从第一个循环调用完成;
for (uploadCount = 0; uploadCount < ImageList.size(); uploadCount++) {
imagePath = productRef.child(UID).child("images").push().getKey();
Uri IndividualImage = ImageList.get(uploadCount);
StorageReference ImageName = productImagesRef.child(UID).child(imagePath);
//Compress Images
Bitmap bmp = null;
try {
bmp = MediaStore.Images.Media.getBitmap(getContentResolver(), IndividualImage);
} catch (IOException e) {
e.printStackTrace();
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 25, baos);
byte[] data = baos.toByteArray();
//End of compressing
//start on uploading compressed
ImageName.putBytes(data).addOnSuccessListener(taskSnapshot -> ImageName.getDownloadUrl()
.addOnSuccessListener(uri -> {
String url = String.valueOf(uri);
StoreLink(url);
}));
}
这是 firebase 实时上传:
private void StoreLink(String url) {
HashMap<String ,Object> hashMap = new HashMap<>();
hashMap.put("image", url);
hashMap.put("id", imagePath);
dialog.dismiss();
assert imagePath != null;
productRef.child(UID).child("images").child(imagePath).updateChildren(hashMap);
}
【问题讨论】:
-
很可能使用recursive function call,对吧?