【发布时间】:2020-02-20 13:52:31
【问题描述】:
我正在我的文档参考中注册快照侦听器。第一次,我得到元数据 isfromCache 为真,其他时候我得到假。它应该相反,因为没有文档正在更改。我检查了这个值只是为了确保我第一次读取后的数据是从缓存中读取的。
DocumentReference basicRef = usersRef.collection(DETAILS).document(BASIC_DETAILS);
ListenerRegistration basicListener = basicRef.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot snapshot,
@Nullable FirebaseFirestoreException e) {
if (e != null) {
return;
}
if (snapshot != null && snapshot.exists()) {
Log.d("debug", "Current data basic: " + snapshot.getMetadata().isFromCache());
BasicDetails basicDetails = snapshot.toObject(BasicDetails.class);
loadData(basicDetails);
} else {
Log.d("debug", "Current data: null");
}
}
});
【问题讨论】:
标签: android firebase google-cloud-firestore