【发布时间】:2020-08-19 21:56:53
【问题描述】:
我正在尝试使用用户 ID 创建一个孩子。我在这里创建用户时找到了ID,并在logcat中获取了userID:
final String fullName = findViewByid(R.id.fullName);
.
. // Other strings declared here
.
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser newUserID = mAuth.getCurrentUser();
userID = newUserID.getUid();
Log.w(TAG, "AuthenticationComplete:true //id:" + userID);
检查了 logcat,看到了 userID 变量。检查auth控制台,得到“authentication complete:true //id:userid”。
这就是问题所在。
public void onComplete(@NonNull Task<AuthResult> task) {
.
.
.
});
Log.w(TAG, "AuthenticationComplete:true //id:" + userID);
BasicUser newUser = new BasicUser(fullName, uname, userEmail, password, confirmPassword, city, newState, zip, type);
Log.w(TAG, "idcheck:" + userID);
**reference.child(userID).setValue(newUser);**
我再次检查了我的 logcat,我得到了“authentication complete:true //id:userid” “idcheck:空”。
我尝试过的事情:
- 将孩子更改为 uname(另一个字符串变量)。数据已按预期发布到实时数据库中
- 将“”“”放在用户 ID 周围。不知道我认为它会做什么,但值得一试
- 将所有字符串和底部代码放在 onComplete 方法中
我之前有它工作过,但不确定如何工作,所以我知道这是可能的。蒂亚!
更新:
我将变量设为全局变量而不是最终变量。它现在按预期工作。
public class(){
String fullName;
public void signUp(){
public void onComplete(@NonNull Task<AuthResult> task) {
});
Log.w(TAG, "AuthenticationComplete:true //id:" + userID);
BasicUser newUser = new BasicUser(fullName, uname, userEmail, password, confirmPassword, city, newState, zip, type);
Log.w(TAG, "idcheck:" + userID);
reference.child(userID).setValue(newUser);
【问题讨论】:
-
请编辑问题以完整显示非工作代码,而不是将其分解。
标签: java android firebase firebase-authentication