https://kotlinlang.org logo
#android
Title
# android
s

Saran Sankaran

05/15/2020, 5:51 AM
I assume you mean to say, you want to return after
checkOrginization()
method after completing the loop in success listener. Am’I getting it right?
r

Remon Shehata

05/15/2020, 7:48 AM
yes, right
s

Saran Sankaran

05/15/2020, 7:52 AM
That’s not possible, because when you call
checkOrganization()
that function is called immediately. In that function you are creating listener
addOnSuccessListener{}
, that will be called whenever there is a success. Or might never be called in the case of failure, you cannot keep
checkOrganization()
blocked until then.
r

Remon Shehata

05/15/2020, 7:53 AM
yes I understand that. but I don't know how to solve it
s

Saran Sankaran

05/15/2020, 7:56 AM
Whatever action you want to do, after you have completed success listener, you can move it into a separate function. And you can call that function from
addOnSuccessListener{}
r

Remon Shehata

05/15/2020, 8:01 AM
I will keep looking. thanks
s

Saurabh

05/15/2020, 11:35 AM
If you have the scope to make this method suspended, you can use
suspendCancellableCoroutine
and resume the coroutine with success, whenever you want.
r

Remon Shehata

05/15/2020, 11:36 AM
I created my own listener. I used to to it in Java
I need to learn about Co routines first
s

Saurabh

05/15/2020, 11:38 AM
Glad to know you worked it out for yourself.
r

Remon Shehata

05/15/2020, 11:41 AM
Thanks bro