when i debug it, the return runs first, then the mCode = document.get("code").toString() runs ;-;
mCode is a lateinit var, so when it returns, mCode isnt initialized
when i debug it, the return runs first, then the mCode = document.get("code").toString() runs ;-;
mCode is a lateinit var, so when it returns, mCode isnt initialized
It is because the .addOnSuccessListener()
and .addOnFailureListener()
are asynchronous methods, so they will be executed just when receive the result from the call.
What you can do is like:
...
.get().addOnSuccessListener(...{
override fun onSucess(document: DocumentSnapshot) {
onSuccessAction(document)
}
})
...
private fun onSuccessAction(document: DocumentSnapshot) {
mCode = document.get("code").toString()
if (code == mCode) {
// Do anything...
}
}