Monday, 18 November 2019

E-mail registered users displayName is not displayed after first login in Navigation Header (Firebase)

When a user logs in for the first time in my app he gets to a "Welcome screen" where he types in a username. After clicking on a button he gets to the MainActivity where in the NavigationDrawer should be his created username. The problem is that the username is only displayed after he logs out and in again.

The displayName is also displayed in another TextView in another activity where it is displayed in the correct way. In that activity I use this code:

namePlayer1 = view.findViewById(R.id.name_player_1);
        FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
        String userName =user.getDisplayName();
        namePlayer1.setText(userName);

So if you compare this with the code below you see that the problem only occurs when using a NavigationDrawer.

I know that this has been a bug in the Firebase Android SDK v9.8.0 but this should have been resolved by now right?

Here is the question I am referring to: displayName showing null after creating user with Firebase Auth

Here is my MainActivity which has a Navigation Drawer:


...

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

            setContentView(R.layout.activity_main);
            DrawerLayout drawer = findViewById(R.id.drawer_layout);
            NavigationView navigationView = findViewById(R.id.nav_view);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                    this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
            drawer.addDrawerListener(toggle);
            toggle.syncState();
            navigationView.setNavigationItemSelectedListener(this);

            // Displays the username in the nav_header
            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            String userName = user.getDisplayName();
            View header = navigationView.getHeaderView(0);
            TextView text = header.findViewById(R.id.username);
            text.setText(userName);


from E-mail registered users displayName is not displayed after first login in Navigation Header (Firebase)

No comments:

Post a Comment