更新说明
如何在用户注册的同时将用户发送到数据库。我的旧代码工作但不再工作了,我错过了什么?
当用户登录并在mainActivy()中启动用户的地理标记时,它会与数据库建立连接。但我需要在用户结束并立即登录时立即保存。所以我的登录活动中的代码错误。
登录活动:
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d("TAG", "onAuthStateChanged:signed_in:" + user.getUid());
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
// Authenticated successfully with authData
Map<String, Object> map = new HashMap<String, Object>();
map.put("email", email);
ref.child("users").child(user.getUid()).updateChildren(map);
Intent intent = new Intent(LoginActivity.this, MainReal.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
} else {
// User is signed out
Log.d("TAG", "onAuthStateChanged:signed_out");
}
}
};
依赖关系
compile "com.google.firebase:firebase-database:9.0.0"
compile 'com.google.firebase:firebase-auth:9.0.0'
compile 'com.firebaseui:firebase-ui-database:0.4.0'
compile 'com.firebaseui:firebase-ui-auth:0.4.0'
答案 0 :(得分:0)
问题在于String email
是null
以下解决了问题
map.put("email", user.getEmail());