I want to show prograssbar with the help of Alert.Dialog while saving data to database. but after registration the program crashes.
A method that gives an error after running:
private void saveData() {
if (isPickPhoto) {
StorageReference mRef = FirebaseStorage.getInstance().getReference().child("ShopList Images")
.child(imgUri.getLastPathSegment());
AlertDialog.Builder builder = new AlertDialog.Builder(AddShopListActivity.this);
builder.setCancelable(false);
builder.setView(R.layout.progress_layout);
AlertDialog dialog = builder.create();
dialog.show();
mRef.putFile(imgUri).addOnSuccessListener(taskSnapshot -> {
Task<Uri> uriTask = taskSnapshot.getStorage().getDownloadUrl();
while (!uriTask.isComplete()) ;
Uri urlImage = uriTask.getResult();
imageUrl = urlImage.toString();
uploadData();
dialog.dismiss();
}).addOnFailureListener(e -> {
dialog.dismiss();
});
} else {
Toast.makeText(this, "Yükleme yapmak için galeriden bir resim seç", Toast.LENGTH_SHORT).show();
}
}
but when I use it to update the data it works fine.
method that works flawlessly:
private void updateData() {
AlertDialog.Builder builder = new AlertDialog.Builder(AddShopListActivity.this);
builder.setCancelable(false);
builder.setView(R.layout.progress_layout);
AlertDialog dialog = builder.create();
dialog.show();
if (isPhotoChanged) {
StorageReference storageReference = FirebaseStorage.getInstance().getReference().child("ShopList Images").child(imgUri.getLastPathSegment());
storageReference.putFile(imgUri).addOnSuccessListener(taskSnapshot -> {
Task<Uri> uriTask = taskSnapshot.getStorage().getDownloadUrl();
while (!uriTask.isComplete()) ;
Uri urlImage = uriTask.getResult();
imageUrl = urlImage.toString();
uploadData();
dialog.dismiss();
}).addOnFailureListener(e -> {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
});
} else {
imageUrl = oldImageUrl;
uploadData();
dialog.dismiss();
}
}
what can i do for using AlertDialog in saveData() metod ?
i want to show progressbar with Dialog.Alert.builder. but it crashes after data saved.
LogCat screen: