Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase, is it possible to place verifyPhoneNumber outside activity without passing activity reference to it?

I'm trying to implement Firebase phone number authentication. Official docs says that I need to call

PhoneAuthProvider.getInstance().verifyPhoneNumber(
    phoneNumber,        // Phone number to verify
    60,                 // Timeout duration
    TimeUnit.SECONDS,   // Unit of timeout
    this,               // Activity (for callback binding)
    mCallbacks);        // OnVerificationStateChangedCallbacks

And pass my activity reference for callback binding.

There is another overloaded method in docs, which accepts TaskExecutors.MAIN_THREAD (the Executor used to call the OnVerificationStateChangedCallbacks callbacks), instead of activity ref.

That's what I needed. In this case

phoneAuthProvider.verifyPhoneNumber(
        phone,
        1,
        TimeUnit.MINUTES,
        TaskExecutors.MAIN_THREAD,
        callbacks,
        resendingToken
);

The code works perfectly. But the problem is: callbacks continue their work in a background infinitely long. I didn't find any methods in the documentation to stop these callbacks.

So, how can I manually remove these callbacks, when I don't need them anymore?

like image 606
trueangle Avatar asked Jun 23 '17 21:06

trueangle


1 Answers

I think you can use TaskExecutors.MAIN_THREAD instead.

PhoneAuthProvider.getInstance().verifyPhoneNumber(
    phoneNumber, // Phone number to verify
    60, // Timeout duration
    TimeUnit.SECONDS, // Unit of timeout
    TaskExecutors.MAIN_THREAD, // Executor
    verifyNumberCallback
)
like image 150
Isquierdo Avatar answered Nov 12 '22 07:11

Isquierdo