'Firebase realtime database with await function in kotlin
I have a trouble using firebase realtime database, I found the reason. I'm using await function when get the data. When network is offline, it throws an error and app is closing. Can you give me the reason? I have to return this result for use it at the another space that I have to use await function for get the result. Thanks for reading. here is my code below.
lateinit var database: DatabaseReference
database = Firebase.database.reference
val test: DataSnapshot? = database.child("issuers").child(issuerguid).child("test").get().await()
Solution 1:[1]
try this
fun test(action :(snapShot :DataSnapshot) -> Unit){
database.child("issuers").child(issuerguid).child("test").get()
.addOnSuccessListener{ snapshot ->
action(snapShot)
}
}
//usage
test{
//use snapshot here
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
