Android Firebase onDataChange is not called?

前端 未结 2 1032
南旧
南旧 2020-12-11 22:37

I have more than 40,000 nodes in my Firebase Database. But whenever I am trying to read a key from my Android code, the onDataChange method is not getting calle

相关标签:
2条回答
  • 2020-12-11 23:01

    First thing to do is to check you have correct permissions to read from your database. Go to https://console.firebase.google.com/project/[your_database_url]/database/rules and check . Not ideal in prod, but for testing you can set read to true

      {
      "rules": {
         ".read": true,
         ".write": "auth != null"
       }
      }
    

    Next gotcha is to remember that the listeners are asynchronous fire and forget calls. So any manipulations to the data should be done once the data has been received in the onDataChange() method.

    0 讨论(0)
  • 2020-12-11 23:15

    Open Firebase link -> Database -> Rules -> Probably values here are false in your case. Make it true as the following.

      {
        "rules": {
          ".read": true,
          ".write": true
        }
      }
    
    0 讨论(0)
提交回复
热议问题