I don't know if this is common or what. But I only have one Toast when it successfully deleted the data from Realtime Database
here's my code btw.
holder.btndel_stud.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Delete Student Record");
alert.setMessage("Are you sure you want to delete");
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Users");
final String uniqueKey = addingStudentsArrayList.get(position).getUniqueid();
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
databaseReference.child(uniqueKey).removeValue().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Toast.makeText(context, "Student Account/Record has been deleted..", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(context, "Something went wrong...", Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
Toast.makeText(context, error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "Cancelled", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
alert.show();
}
});
}
basically it toast twice on my mobile phone, even tho I called it only once. But yeah it toast once in my emulator. I genuinely don't know what's happening since there's no message indicating why it's toasting twice.
Toast.makeText(context, "Student Account/Record has been deleted..", Toast.LENGTH_SHORT).show();
The solutions I've tried: Reinstall the app on my phone, clear cache and clear storage but no luck. Thank you!