Reputation: 619
How do you use Android Firebase phone authentication with the first Activity holding the form that gets the phone number of the user, and the second Activity processes the confirmation code.
Upvotes: 0
Views: 431
Reputation: 2411
Dale, I'd recommend one Activity and two Fragments for UI transition and you only do verifyPhoneNumber in your Activity. Based on the callback, you can transition from PhoneNumberInputFragment to VerificationCodeInputFragment.
FirebaseUI is open sourced and you can take a look at code there: https://github.com/firebase/FirebaseUI-Android/tree/master/auth/src/main/java/com/firebase/ui/auth/ui/phone
If you really want 2 Activity for whatever reason:
a) if onVerificationComplete is called back (instant validation), skip 2nd Activity b) if onCodeSent is called back, transition to 2nd Activity
2 b) Since 2nd Activity is started & 1st Activity is stopped, the listener of the 1st Activity is auto-detached. In 2nd Activity, call verifyPhoneNumber again. Google Play services will keep the session alive and no 2nd SMS will be sent. You will get onCodeSent immediately with the same verificationId.
Upvotes: 2