用户注册成功时添加值

时间:2017-09-18 12:56:09

标签: android firebase-realtime-database firebase-authentication

我创建了一个Android用户登录和注册应用程序。我想要当用户注册成功时,名称点和值0将被添加到数据库。 enter image description here

这是我的注册码:

//logging in the user
        firebaseAuth.signInWithEmailAndPassword(email, password)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        progressDialog.dismiss();
                        //if the task is successfull
                        if(task.isSuccessful()){
                            //start the profile activity
                            finish();
                            startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
                        }else{
                            //display some message here
                            Toast.makeText(LoginActivity.this,"Error Email Or Password",Toast.LENGTH_LONG).show();
                        }
                        progressDialog.dismiss();
                    }
                });

1 个答案:

答案 0 :(得分:0)

因此,为了实现这一点,请直接在引用中使用setValue()方法,如下所示:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
rootRef.child(userId).child("Points").setValue(0);

其中userId是经过身份验证的特定用户的ID。