简体   繁体   中英

In Android, get recently created user's UID in Firebase

I am attempting to create a user and for adding additional information I want to get the UID of recently created user in Android.

I have a JSON object of users in which i store user information under user's unique UID.

I want to store user's additional information as soon as the user is created. In the createUserWithEmailAndPassword() method it says that if user is successfully created, it is logged in.

I tried getting the UID but it was not possible. I have created a Progress Dialog before creating and I dismiss it after saving the user information in the real time database.

If I understand well your situation, you can get the user id in this way:

I get the recently created user with task.getResult().getUser().getUid()

auth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(SignUpActivity.this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {

                        if (!task.isSuccessful()) {
                            /*Toast.makeText(SignUpActivity.this, "Authentication failed." + task.getException(),
                                    Toast.LENGTH_SHORT).show();*/

                        } else {
                            // THE USER ID
                            task.getResult().getUser().getUid();

                        }
                    }
                });

After the task has been successfully completed you can get the users UID calling the following user.getUid().

If you followed the documentation you should have a class variable defined such as "FirebaseUser user;".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM