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


This Content is from Stack Overflow. Question asked by KayraOz

I wrote a simple authentification:

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

                    }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:

public void 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);


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?


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?