trying to delete firestore document, crash error, restart app and not even debuger error message

Asked

Viewed 47 times

0

I’m trying to delete a document, however the app simply closes itself. I’ve tried everything I know, but the error persists. I don’t understand why. The code itself is correct.

The general way is this:

/tutors/zqfcZEX1E4UFEaVcocR/pets

Has anyone seen similar mistake?

dbFirestore.collection("/tutores").document(mTutorID).collection("/pets").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                @Override
                public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                    for (int i = 0; i<queryDocumentSnapshots.getDocuments().size(); i++){
                        String fotonome = queryDocumentSnapshots.getDocuments().get(i).get("foto_nome").toString();
                        StorageReference storageRef = firebaseStorage.getReference();
                        StorageReference  petRefFoto = storageRef.child("pets/"+fotonome);
                        petRefFoto.delete();
                        queryDocumentSnapshots.getDocuments().get(i).getReference().delete();
                    }

                    StorageReference storageRef = firebaseStorage.getReference();
                    StorageReference  tutorRefFoto = storageRef.child("tutores/"+mTutorFotoNome);
                    tutorRefFoto.delete();

                    dbFirestore.collection("/tutores").document(mTutorID).delete().addOnSuccessListener(new OnSuccessListener<Void>() {
                        @Override
                        public void onSuccess(Void aVoid) {                            AbreLogin();
                        }
                    });

                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Toast.makeText(getBaseContext(), "Ocorreu algum problema, NÃO foi possivel apagar as contas dos pets, tente novamente!", Toast.LENGTH_LONG).show();
                }
            });

Error happens when this root document is deleted:

dbFirestore.collection("/tutores").document(mTutorID).delete().addOnSuccessListener(new OnSuccessListener<Void>() {
                        @Override
                        public void onSuccess(Void aVoid) {
                            AbreLogin();
                        }
                    });

The general way is this

/tutors/zqfcZEX1E4UFEaVcocR/pets

  • What record of log in Android Studio?

  • it does not give error message, it deletes the document, closes the Activity and even without any command it talks back to previous Activity which has a get with addSnapListener() it obviously from error by no longer having the document.... pq it still does read on a get with addSnapshotListener() from Activity that is no longer showing? what should I do???

1 answer

0

I found out that it is just remove the Snapshotlistener by registering them as follows: I create the variable to keep them

ListenerRegistration registration;

registration = dbFirestore.collection("/tutores").whereEqualTo("email", TutorEmail ).addSnapshotListener()...


and then remove them when necessary:

if (registration!= null) {
    registration.remove();
    registration = null;
}
  • in thinking that I lost two days, only repeating the same thing, error in the code I knew I had not, was missing a bug in logic ne, rss

Browser other questions tagged

You are not signed in. Login or sign up in order to post.