Issue
This Content is from Stack Overflow. Question asked by KayraOz
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?
Solution
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.