0

So the flow will go like this:

  1. user login with email and password via firebase
  2. if email is verified, they will go to the main activity else they will go to the verify email activity

What I wanted to do is when they are at the verify email activity, I will send a verification email in onCreate method, then if the email is verified (in run time), I will send the user to the main activity.

I know the function to check if user verify email is by

firebaseAuth.getCurrentUser().isEmailVerified()

The problem here is how can I use this function (or others) to check if the user verify their email in real time.

I've tried doing this using a while loop, but it does not work out as expected :

firebaseAuth.getCurrentUser().sendEmailVerification().addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid) {
            //verify email sent
            Alert("Verification email send");

            //PROBLEM STARTS HERE
            boolean v = true;
            while(v){
                if(firebaseAuth.getCurrentUser().isEmailVerified()){
                    v = false;
                    break;
                }
            }
            if(!v){
                Alert("Email verified");
                startActivity(new Intent(getApplicationContext(), MainActivity.class));
                finish();
            }
        }
    });
a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
Xiang
  • 13
  • 3

1 Answers1

1

You can add keypress event in the function. If user press any key, then you will check the email id at that time by calling the function.You don’t need while loop. Just call the function if you find that user pressed any key.

sample code :

@Override
public Boolean onKeyUp(int keyCode, KeyEvent event) {
    if(firebaseAuth.getCurrentUser().isEmailVerified()){
        startActivity(new Intent(getApplicationContext(), MainActivity.class));
        finish();
    }
    return super.onKeyDown(keyCode, event);
}

Try something like this instead of while loop.

Aayush Shah
  • 584
  • 1
  • 8
  • 17