0

I have an activity where I want the user to wait until email account is verified, but it is not taking the user to mainActivity once account is verified, how should I address this?

See my code below;

    user.sendEmailVerification();

    final Handler handler = new Handler();
    final int delay = 10000; //milliseconds

    handler.postDelayed(new Runnable() {
        public void run() {

            if (user.isEmailVerified()) {
                startActivity(new Intent(VerificationEmailActivity.this, MainActivity.class));
                Toast.makeText(VerificationEmailActivity.this, R.string.spend_wisely, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(VerificationEmailActivity.this, "Check your email!", Toast.LENGTH_SHORT).show();
            }
            handler.postDelayed(this, delay);
        }
    }, delay);

}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

0

Since the actual verification of the user happens outside of your Android app (in your browser), the app is not aware that it happens. This means that the app only detects the user's updated state once it auto-refreshes the token, which can take up to an hour.

To detect it earlier, you can reload the profile by calling reload(), or forcing the refresh of the ID token by calling getIdToken(true).

This has been covered quite a few times already, so also check out:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 2
    It's not so much about where as it is about *when*. It needs to run after the user has clicked the verification link in their email. The answers in the links give some ideas, but most common are to: 1) run periodically, 2) run when the app regains the focus (as that may be the user switching back from their mail app, 3) provide a tap target for the user to retry, or 4) all of those. – Frank van Puffelen Apr 06 '22 at 22:55