【发布时间】:2022-11-23 03:14:24
【问题描述】:
我是使用 firestore 和 android studio 的新手,正在尝试根据当前登录用户将数据从 Firestore 加载到 android studio 应用程序。这是我一直在测试的代码,但它似乎没有显示任何数据。任何帮助,将不胜感激。
public void userInfo(){
FirebaseFirestore db = FirebaseFirestore.getInstance();
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DocumentReference documentReference = db.collection("users").document(userId);
documentReference.get().addOnCompleteListener(task -> {
if(task.isSuccessful()){
DocumentSnapshot snapshot = task.getResult();
if(snapshot!=null){
if(snapshot.exists()){
String name1 = String.valueOf(snapshot.get("name:"));
name.setText(name1);
}
}
}
});
}
【问题讨论】:
-
if(task.isSuccessful()){如果任务不成功怎么办?或者if(snapshot.exists())是假的? -
请编辑您的问题并添加 a_local_nobody 要求的信息,同时请用@回复。
标签: android google-cloud-firestore