Firebase Firestore侦听器已跳过

时间:2018-11-17 03:52:39

标签: android android-studio google-cloud-firestore

在阅读Firestore数据时,我遵循了各种文档。但是,为什么这两个侦听器方法不执行?当我通过Android Studio调试时,它们都通过执行传递。

尝试1:

DocumentReference docRef = this.db.collection("gallery").document("animal");
    docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
        @Override
        public void onComplete(@NonNull Task<DocumentSnapshot> task) {
            if(task.isSuccessful()) {
                DocumentSnapshot documentSnapshot = task.getResult();
                if(documentSnapshot.exists()) {
                    Log.d(TAG, "onComplete: " + documentSnapshot.getData());
                } else {
                    Log.d(TAG, "onComplete: no data");
                }
            } else {
                Log.d(TAG, "onComplete: failed");
            }
        }
    });

尝试2:

DocumentReference docRef = this.db.collection("gallery").document("animal");
        docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
            @Override
            public void onSuccess(DocumentSnapshot documentSnapshot) {
                if(documentSnapshot.exists()) {
                    Map<String, Object> mapData = documentSnapshot.getData();
                } else {
                    Log.d(TAG, "loadGalleryItemsFromFirestore: not exixt");
                }
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.e(TAG, "loadGalleryItemsFromFirestore: ", e);
            }
        });

数据在Firestore上可用,如下所示:

enter image description here

我通过了吗?

0 个答案:

没有答案