2017-05-30 80 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

我最終通過切換模擬器來解決這個問題。我不完全確定究竟是什麼問題,但這對我有用

相關問題