hwo to set username in firebase authentication android code example

Example 1: how to check the current user in firebase android

@Override
public void onStart() {
    super.onStart();
    FirebaseUser currentUser = mAuth.getCurrentUser();
    if (currentUser == null) {
        // No user is signed in
    } else {
        // User logged in
    }
}

Example 2: how to check if user is logged in firebase android and then load another activity

private FirebaseAuth firebaseAuth;
 FirebaseAuth.AuthStateListener mAuthListener;
    firebaseAuth = FirebaseAuth.getInstance();

      mAuthListener = new FirebaseAuth.AuthStateListener(){
                @Override
                public  void  onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth){
            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        if(user!=null){
        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
}
                }


            };