Android 在firebase中,通过使用电子邮件和密码身份验证,我希望使用推送功能添加用户数据

Android 在firebase中,通过使用电子邮件和密码身份验证,我希望使用推送功能添加用户数据,android,firebase-realtime-database,firebase-authentication,Android,Firebase Realtime Database,Firebase Authentication,我使用firebase作为后端。用户正在使用电子邮件和密码进行身份验证。我正在使用push在实时数据库中存储其他数据,如姓名和电话。如何检索用户数据以显示在用户配置文件上,因为生成了唯一ID。 下面是我存储数据的活动 public class UserActivity extends AppCompatActivity { private EditText inputName, inputPhone, inputNatId,inputDOB; private TextInputL

我使用firebase作为后端。用户正在使用电子邮件和密码进行身份验证。我正在使用push在实时数据库中存储其他数据,如姓名和电话。如何检索用户数据以显示在用户配置文件上,因为生成了唯一ID。 下面是我存储数据的活动

public class UserActivity extends AppCompatActivity {
    private EditText inputName, inputPhone, inputNatId,inputDOB;
    private TextInputLayout inputLayoutName, inputLayoutPhone, inputLayoutNatId;
    private Button Complete;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        inputName = (EditText) findViewById(R.id.input_names);
        inputPhone = (EditText) findViewById(R.id.input_phone);
        inputNatId = (EditText) findViewById(R.id.input_natid);
        inputDOB = (EditText) findViewById(R.id.input_DOB);
        inputLayoutName = (TextInputLayout) findViewById(R.id.input_layout_names);
        inputLayoutPhone = (TextInputLayout) findViewById(R.id.input_layout_phone);
        inputLayoutNatId = (TextInputLayout) findViewById(R.id.input_layout_natid);
        Complete = (Button) findViewById(R.id.btncomplete);


        Firebase.setAndroidContext(this);






        Complete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Firebase ref = new Firebase(Config.FIREBASE_URL);


                String names = inputName.getText().toString();
                String phone = inputPhone.getText().toString().trim();
                String natid = inputNatId.getText().toString().trim();
                String dob = inputDOB.getText().toString().trim();

                if (TextUtils.isEmpty(names))
                {
                    inputName.setError("Enter Full Names");
                }
                if (inputPhone.length() < 10 && inputPhone.length() > 10)
                {
                    inputPhone.setError("Phone should be 10 digits");
                }
                if (inputNatId.length() < 8 && inputNatId.length() > 8)
                {
                    inputNatId.setError("ID should be 8 digits");
                }
                if (TextUtils.isEmpty(phone))
                {
                    inputPhone.setError("Enter Phone Number");
                }
                if (TextUtils.isEmpty(natid))
                {
                    inputNatId.setError("Enter National ID");
                }
                if (TextUtils.isEmpty(dob))
                {
                    inputDOB.setError("Enter Date Of Birth");
                }
                else
                {




                    Firebase newref = ref.child("Person");

                    Map<String,String > users = new HashMap<String, String>();
                    users.put("names",names);
                    users.put("phone",phone);
                    users.put("national id",natid);
                    users.put("dob",dob);

                    newref.push().setValue(users);

                    Firebase postref = newref.push();
                    String postID = postref.getKey();


                    if (true){
                        Runnable runnable = new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(getApplicationContext(),"Registration Successful",Toast.LENGTH_LONG).show();
                                Intent intent = new Intent(getApplicationContext(),LoginActivity.class);
                                startActivity(intent);
                                finish();
                            }
                        };

                        android.os.Handler handler = new android.os.Handler();
                        handler.postDelayed(runnable, 1000);
                    }
                    else {
                        Toast.makeText(getApplicationContext(),"Registration Error",Toast.LENGTH_LONG).show();
                    }
                }



            }
        });


    }
这是我的实时数据库

barapp-689c1

Person

-KP2YEDe3nhzlW0s4ckH

dob: 27/04/1996

names: Mark K

national id: 01234567

    phone: 0727286122

-KP3bKyKGh_PeHCEisjG

dob: 30/6/1990

names: Bruno M

national id: 12345698

phone: 0721241201

我应该使用此方法还是使用set方法如果存储的数据具有自然键,则通常应将该数据存储在其自然键下。存储用户就是一个很好的例子。由于用户由其
uid
标识,因此存储由其
uid
键入的用户列表最有意义

ref.child("users").child(user.getUid()).setValue(userDataThatYouWantToSave);

这是我想要检索而不是保存的数据
ref.child("users").child(user.getUid()).setValue(userDataThatYouWantToSave);