Answer the question
In order to leave comments, you need to log in
Saving login and password in the application (Android Studio)?
How to save the login and password of the user who entered his data when logging in, for example, to his page? I just know that SharedPreference should be used here, but I don't know how to insert it into my code correctly.
here is the code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_password_em);
mAuth = FirebaseAuth.getInstance();
ETemail = (EditText) findViewById(R.id.et_email);
ETpassword = (EditText) findViewById(R.id.et_password);
findViewById(R.id.btn_sign_in).setOnClickListener(this);
findViewById(R.id.btn_registration).setOnClickListener(this);
}
@Override
public void onClick(View view) {
if(view.getId() == R.id.btn_sign_in)
{
signin(ETemail.getText().toString(),ETpassword.getText().toString());
}else if(view.getId() == R.id.btn_registration)
{
registration(ETemail.getText().toString(),ETpassword.getText().toString());
}
}
public void signin(String email, String password) {
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(PasswordEM.this, "Авторизация прошла успешно", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(PasswordEM.this,ListTasks.class);
startActivity(intent);
} else
Toast.makeText(PasswordEM.this, "Авторизация провалена", Toast.LENGTH_SHORT).show();
}
});
}
public void registration(String email,String password){
mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful())
{
Toast.makeText(PasswordEM.this, "Регистрация прошла успешно", Toast.LENGTH_SHORT).show();
}
else
Toast.makeText(PasswordEM.this, "Регистрация провалена", Toast.LENGTH_SHORT).show();
}
});
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question