【发布时间】:2024-05-21 22:40:02
【问题描述】:
我在从 Firestore 获取数据时遇到问题,在 Java 代码中我们可以这样做:
DocumentReference docRef = db.collection("cities").document("SF");
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document != null) {
Log.d(TAG, "DocumentSnapshot data: " + task.getResult().getData());
} else {
Log.d(TAG, "No such document");
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
}
});
但在 Kotlin 中,当我尝试覆盖 onComplete 函数时,它不可用。那么,我怎样才能得到“任务”呢?
【问题讨论】:
标签: android firebase kotlin google-cloud-firestore