0

code

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

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Hello, please post codes as text not screen shots .. this allows a one that can offer help to test and also pics don't remain long on web, so the quest may be distorted in the future – Zain Apr 25 '21 at 23:42
  • I tried it, but the code wasnt idented like it expected – Arlysthon Feitosa Apr 26 '21 at 00:06
  • In that case, read https://meta.stackexchange.com/questions/90407/easy-way-to-indent-code, https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks, https://meta.stackexchange.com/questions/207842/how-to-easily-indent-multi-line-code, or https://meta.stackexchange.com/questions/125148/implement-style-fenced-markdown-code-blocks. – Frank van Puffelen Apr 26 '21 at 00:34

1 Answers1

0

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...
    }
}

GuilhermeMagro
  • 321
  • 1
  • 10