For Register user refer below else part:
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
progressBar.setVisibility(View.GONE);
if (task.isSuccessful()) {
Toast.makeText(Register.this, "Account successfully created.",
Toast.LENGTH_SHORT).show();
UserDetails userDetails= new UserDetails(dob,medical_conditon,emergency_contact,emergency_contact_name);
String uId=task.getResult().getUser().getUid();
firebaseDatabase.getReference(uId).setValue(userDetails)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void unused) {
Intent intent=new Intent(getApplicationContext(), Login.class);
//intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);//finish current activity ie register,
//intent.putExtra("email",email);
startActivity(intent);
finish();
}
});
// Sign in success, update UI with the signed-in user's information
//FirebaseUser user = mAuth.getCurrentUser();
} else {
// If sign in fails, display a message to the user.
try{
throw task.getException();
}catch (FirebaseAuthUserCollisionException e){
editTextEmail.setError("Email already registered");
editTextEmail.requestFocus();
}
catch (FirebaseAuthInvalidCredentialsException e){
editTextEmail.setError("Email is invalid or already in use");
editTextEmail.requestFocus();
}
catch (Exception e)
{
Log.e(TAG, e.getMessage());
Toast.makeText(Register.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
Toast.makeText(getApplicationContext(), "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
}
});
For Login part refer below:
else {
// If sign in fails, display a message to the user.
try{
throw task.getException();
}catch (FirebaseAuthInvalidCredentialsException e){
editTextPassword.setError("Invalid Password");
editTextPassword.requestFocus();
}
catch (FirebaseAuthInvalidUserException e) {
editTextEmail.setError("Email does not exist!");
editTextEmail.requestFocus();
}
catch (Exception e)
{
Log.e(TAG, e.getMessage());
Toast.makeText(Login.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
Toast.makeText(Login.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}