public class MainActivity extends AppCompatActivity {
private static final String TAG = "100";
FirebaseFirestore db;
String checkCode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db= FirebaseFirestore.getInstance();
db.collection("Users")
.whereEqualTo("level", "admin")
.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (!queryDocumentSnapshots.isEmpty()) {
List<DocumentSnapshot> list = queryDocumentSnapshots.getDocuments();
for (DocumentSnapshot d : list) {
checkCode = (String) d.get("kode");
Toast.makeText(MainActivity.this, "From inside : "+checkCode, Toast.LENGTH_LONG).show();
}
}
}
});
Toast.makeText(MainActivity.this, "From outside : "+checkCode, Toast.LENGTH_LONG).show();
}
}
我仍然对如何从 Cloud Firestore 获取数据感到困惑。所以我尝试制作一个简单的代码来从那里获取数据。我输入了 1111 代码。
运行程序后,里面的吐司给我:
From inside : 1111
但是外面的吐司给我:
From outside : null
这是为什么?我该如何解决?
牧羊人nacy
鸿蒙传说
繁星点点滴滴
慕雪6442864
相关分类