I am getting this error when trying to retrieve image from firebase storage.
java.lang.IllegalStateException: Task is not yet complete on upload task.
Code:-
Uri imageUri = data.getData();
final StorageReference filePath = UserProfileImageRef.child(currentUserID + ".jpg");
filePath.putFile(imageUri)
.addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if (task.isSuccessful()) {
Toast.makeText(ProfileActivity.this, "Profile Image Uploaded", Toast.LENGTH_SHORT).show();
String downloadUri = filePath.getDownloadUrl().getResult().toString();
UserRef.child("profileImage").setValue(downloadUri).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Intent selfIntent = new Intent(ProfileActivity.this,ProfileActivity.class);
startActivity(selfIntent);
Toast.makeText(ProfileActivity.this, "Profile image uploaded to database", Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
}
else {
String message = task.getException().getMessage();
Toast.makeText(ProfileActivity.this, "Error Occurred" + message, Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
}
}
});
}
}
});