I am working on a Multiplayer Board Game in android studio, I want to update the Values I got from one player and show it to another and vice versa, but when I got updated value, I can't use it in my app methods because my local variable will not update instantly and gave null value, and also I cant just put my whole game code in that valueEventListner, or I cant use Handler as it's still not reliable to wait for data update because we don't know, how much time will it take to update values, I can get data from firebase by creating a method which will return what I want
Asked
Active
Viewed 19 times
0

Frank van Puffelen
- 565,676
- 79
- 828
- 807

Rohit Sangwan
- 33
- 1
- 3
-
It's hard to be certain without seeing your code, but I think you're struggling with the fact that data is loaded from Firebase asynchronously. The problem is not so much where you access the variables, as **when** you access them. For a good walkthrough of that problem, and the way to solve it, see https://stackoverflow.com/questions/50434836/getcontactsfromfirebase-method-return-an-empty-list/50435519#50435519 – Frank van Puffelen Sep 23 '20 at 17:14
-
yeah i know it takes time to update data ,and thats why am getting null value , but what to do now , should i put my whole code into valueEventListner, but this will recall whole code when value will change – Rohit Sangwan Sep 23 '20 at 17:19
-
It's impossible to say more without seeing the minimal code that reproduces the problem. See [how to create a minimal, complete, verifiable example](http://stackoverflow.com/help/mcve). – Frank van Puffelen Sep 23 '20 at 17:23