我的导航标题中有一个文本视图,我想在用户更新其显示名称时更新。配置文件成功获取更新,但导航标题中的textview无法更新,我退出并再次登录。
这是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();
}
});
}
请参阅日志。成功更新配置文件后,我在日志中得到旧名称。
签入代码。我写了一条评论。
答案 0 :(得分:0)
这只是firebase中的一个已知问题。如果您使用旧的firebaseAuth。将您的成绩更新为11.0.4