过去几周我一直在研究Android应用程序,并且我一直使用Firebase作为后端。我从firebase读取/写入没有问题,但最近,所有addListenerForSingleValueEvent调用都没有被触发。我不确定为什么它会突然停止阅读。我的数据库规则(用于测试目的)Android Firebase addListenerForSingleValueEvent未调用
"rules": {
".read": true,
".write": true
}
和相关代码
final DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
//searches database for user
//This "LISTENING" println triggers
System.out.println("LISTENING");
mDatabase.child("users").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//This print statement never prints
System.out.println("DATA SNAPSHOT");
for(DataSnapshot user : dataSnapshot.getChildren()){
for(DataSnapshot participant: user.getChildren()) {
//if we have found the participant name
if(participant.getKey().equalsIgnoreCase("Participant Name")){
System.out.println(participant.getValue().toString().trim());
}
}
}
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
}
@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("Error");
}
});
我也有其他几个addListenerForSingleValueEvent调用(即在结构上相似,所以为了简洁起见,我不会交他们在这里),工作很好,直到大约2小时前。可能会发生什么?这可能是Firebase本身的问题吗?我的代码中有什么东西可以忽略?
已解决 - 某种。必须使用不同的模拟器。不清楚问题是什么。 – JohnDoe
go for addValueEventListener(...) – MrCurious