I am logging in normally, but when I close the application, it returns to the login screen. I'm trying to run sharedPreferences but I'm not successful.
public static final String PREF_NAME = "LoginActivityPreferences";
private SharedPreferences mPreferences;
// Metodo onCreate
FirebaseApp.initializeApp(LoginActivity.this);
mAuth = FirebaseAuth.getInstance();
// Metodo shared
private void sharedPreferences(String email, String password) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
mPreferences = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
if (user != null) {
startActivity(new Intent(getApplicationContext(), DashboardActivity.class));
} else {
SharedPreferences.Editor editor = mPreferences.edit();
editor.putString("email", email);
editor.putString("password", password);
editor.commit();
startActivity(new Intent(getApplicationContext(), LoginActivity.class));
}
}
// Metodo de login email e senha
private void singInEmailSenha(final String email, final String password) {
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
sharedPreferences(email, password);
} else {
}
}
});
}