0
I am logging in normally but quado close application, back to 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 {
}
}
});
}
And if the answer is no(I don’t have a checkbox field to stay logged in), you can use the same schema, only there in your application, on the main screen, it would be interesting to have a user option to drop OR quit
– Wallace Baldenebre