2017-05-30 74 views
0

过去几周我一直在研究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本身的问题吗?我的代码中有什么东西可以忽略?

+0

已解决 - 某种。必须使用不同的模拟器。不清楚问题是什么。 – JohnDoe

+0

go for addValueEventListener(...) – MrCurious

回答

0

同样的问题在这里,但我用手机(华为y560 - l01)测试。

编辑:

我解决了这个问题,卸载应用程序,unplunging设备,重新启动设备,并比conecting并再次运行代码。

0

我最终通过切换模拟器来解决这个问题。我不完全确定究竟是什么问题,但这对我有用

相关问题