I'm currently developing an android app and using firebase realtime database. How to pass the user data from the login activity to the navigation header of home activity?
What should I add inside the Login Activity in order to pass the user data to the Navigation header of Home Activity?
User does not need to enter username to login, but I wish to get the username from realtime database and pass it to the Navigation Header as well.
Login.java
firebaseAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
progressDialog.dismiss();
if(task.isSuccessful()){
finish();
startActivity(new Intent(getApplicationContext(),Home.class));
}
else
{
Toast.makeText(LoginActivity.this,"Login failed. Kindly check your email and password.",Toast.LENGTH_SHORT);
}
}
}
Home.java
View headerView = navigationView.getHeaderView(0);
useremail = (TextView)headerView.findViewById(R.id.HVuseremail);
useremail.setText(Common.currentUser.getName());
username = (TextView)headerView.findViewById(R.id.HVusername);
username.setText(Common.currentUser.getName());
I expect my navigation header will display the useremail and username on it.