Android Studio using Firebase: When I login in my app I should get into the "Main activity", but my app jumps back to the login screen

Viewed 18

I wrote a simple authentification:

       auth.signInWithEmailAndPassword(email, password)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        //if login is succesfull open mainActivity
                        if(task.isSuccessful()){
                            Intent intentMainActivity = new Intent(LoginPage.this, MainActivity.class);
                            startActivity(intentMainActivity);

                    }else {
                            Toast.makeText(LoginPage.this, "Failure: "+task.getException(), Toast.LENGTH_LONG).show();

                        } 

When the app starts, the onStart-Method checks if the user is logged in or not:

@Override
public void onStart(){
    super.onStart();
    //Checks if the user is loged in or not, If not go to loginpage

     FirebaseUser currentUser = auth.getCurrentUser();
     if(currentUser == null){
         Intent intentLoginPage = new Intent(MainActivity.this, LoginPage.class);
         startActivity(intentLoginPage);
     }


}

When the user logs in he jumps back to the login screen. I did it exactly as the Firebase documentation showed. I think the user is still null after the login. Due to that it jumps back to the login screen. What can I do to solve this issue?

0 Answers
Related