I am currently using the addListenerForSingleValueEvent
method to retrieve a DataSnapshot
from the local cache as described here: https://firebase.google.com/docs/database/android/read-and-write. Previously I was using Room and executing callables to query the local sqlite database using Executors.newSingleThreadExecutor().submit(callable).get()
, allowing me to store the result in a variable and use it straight away. I can't seem to find a way to do this using Firebase. Is there a way I can use something functionally similar to await
syntax in other languages to wait until I have a result from the local cache?
Asked
Active
Viewed 123 times
0

Pwnion
- 21
- 3
-
1Data is loaded from Firebase (and most modern cloud APIs) asynchronously. Any code that needs the data, needs to be inside the `onDataChange` method or be called from there. See the answers to the questions I linked for some examples of this. – Frank van Puffelen Apr 09 '21 at 03:28
-
Thanks, I think your answer that uses the call back is the closest I'll get. – Pwnion Apr 09 '21 at 04:54
1 Answers
3
I think you want to execute some code after receiving snapshot.But in firebase there is nothing like await
but you can achieve this by putting code in addOnCompleteListener
which you want to perform after getting snapshot.

Purvesh Dodiya
- 594
- 3
- 17