1

我的导航标题中有一个文本视图,当用户更新其显示名称时我想更新它。配置文件成功更新,但导航标题中的文本视图没有更新,我注销并再次登录。

这是 oncreate 方法

firebaseAuth = FirebaseAuth.getInstance();
user = firebaseAuth.getCurrentUser();       
nvDrawer = (NavigationView) findViewById(R.id.nvView);

// Setup drawer view
setupDrawerContent(nvDrawer);

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestIdToken(getString(R.string.default_web_client_id))
        .requestEmail()
        .build();

mGoogleSignInClient = new GoogleApiClient.Builder(this)
        .enableAutoManage(this , new GoogleApiClient.OnConnectionFailedListener() {
            @Override
            public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

            }
        } /* OnConnectionFailedListener */)
        .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
        .build();
headerLayout = nvDrawer.inflateHeaderView(R.layout.nav_header);
name =  headerLayout.findViewById(R.id.dp_name);
user_email= headerLayout.findViewById(R.id.email);
FirebaseAuth.AuthStateListener mAuthListener;

if (user!=null) {
    user_email.setText(user.getEmail());
    name.setText(user.getDisplayName());
    Log.i("name", "Dp name is" + user.getDisplayName());
}

FirebaseAuth auth = FirebaseAuth.getInstance();
FirebaseAuth.AuthStateListener authListener = new FirebaseAuth.AuthStateListener() {
    @Override
    public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
        FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
        if (firebaseUser != null) {
            name.setText(user.getDisplayName());
        }
    }
};

这就是我更新个人资料的方式。

final String user_name = editText.getText().toString();

if (TextUtils.isEmpty(user_name)) {
    editText.setError("This field is required");
    editText.requestFocus();
    Toast.makeText(getApplicationContext(), "Empty", Toast.LENGTH_LONG).show();
} else {
    UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
            .setDisplayName(user_name)
            .build();

    user.updateProfile(profileUpdates).addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                name.setText(user.getDisplayName());

                // Here task is successful but log does not return updated name
                Log.i("Updated", "Dp name is" +user.getDisplayName());
                Toast.makeText(getApplicationContext(), "Profile updated", Toast.LENGTH_LONG).show();
            } else Toast.makeText(getApplicationContext(), "Failed", Toast.LENGTH_LONG).show();
        }
    });
}

请看日志。成功更新配置文件后,我在日志中也得到了旧名称。

签入代码。我写了评论。

4

1 回答 1

0

这只是 firebase 中的一个已知问题。如果您使用的是旧的 firebaseAuth。将您的成绩更新到 11.0.4

于 2018-04-22T18:20:21.770 回答