0

更新说明

如何在用户注册的同时将用户发送到数据库。在我的旧代码中工作,但不再是,我错过了什么?

当用户登录时以及当我在 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'

在此处输入图像描述

4

1 回答 1

0

问题String emailnull

以下解决了问题

map.put("email", user.getEmail());
于 2016-05-21T23:19:14.950 回答