ArrayList gets empty after first snapshot

后端 未结 1 1781
挽巷
挽巷 2021-01-26 00:11

I\'m working with firebase in a android application and something strange ocurred, in my example I need two snapshots, 1 to get the users inside a list ( I use this snapshot to

相关标签:
1条回答
  • This is happening because onDataChange is called asynchronously. This means that the statement that adds users to the list is executed before onDataChange has been called. That's why your list is empty outside that method. So in order to use that lists, you need to use it inside the onDataChange() method.

    For other approach, please visit this post and this post.

    Hope it helps.

    0 讨论(0)
提交回复
热议问题