【发布时间】:2018-10-16 20:57:12
【问题描述】:
我正在创建一个 android 应用程序来存储每个用户的姓名和手机号码,现在当第二个用户更新他的信息时,它正在删除存储在数据库中的第一个用户的信息,我有 2 个片段一个是登录片段(使用firebase auth) 和获取姓名和手机号码的第二个片段。如何分别为每个用户添加信息
这是我的登录代码
btn_signIn = (Button) view.findViewById(R.id.sign_in_btn);
btn_signIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String emailID = username.getText().toString();
String paswd = password.getText().toString();
if (emailID.isEmpty()) {
username.setError("Provide your Email first!");
username.requestFocus();
} else if (paswd.isEmpty()) {
password.setError("Set your password");
password.requestFocus();
}
else if (emailID.isEmpty() && paswd.isEmpty()) {
Toast.makeText(getActivity(), "Fields Empty!", Toast.LENGTH_SHORT).show();
}
else if (!(emailID.isEmpty() && paswd.isEmpty())) {
mAuth.signInWithEmailAndPassword(emailID, paswd)
.addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
// there was an error
if (password.length() < 6) {
// inputPassword.setError(getString(R.string.minimum_password));
} else {
// Toast.makeText(LoginActivity.this, getString(R.string.auth_failed), Toast.LENGTH_LONG).show();
}
} else {
Intent intent = new Intent(getActivity(), HomePageActivity.class);
startActivity(intent);
// finish();
}
}
});
.
}
}
});
这是我在另一个片段中的 firebase 中存储手机号码的代码
new AlertDialog.Builder(getActivity()).setTitle("Please Input Contact Information").setIcon(
android.R.drawable.ic_dialog_dialer).setView(
layout).setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Dialog dialog = (Dialog) dialogInterface;
EditText inputMobile = (EditText) dialog.findViewById(R.id.dialog_et_mobile);
if (inputMobile.getText().toString().isEmpty()){
return;
}
try{
long number = Long.valueOf(inputMobile.getText().toString());
SPManipulation.getInstance(getActivity()).setMobile(inputMobile.getText().toString());
mTextMobile.setText(inputMobile.getText().toString());
String mobile = inputMobile.getText().toString();
DatabaseReference mynum = database.getReference("number");
}catch (Exception e){
Toast.makeText(getActivity(), "Please Input Correct Phone Number!", Toast.LENGTH_SHORT).show();
}
}
}).setNegativeButton("Cancel", null).show();
}
});
谁能帮助为每个用户分别存储信息,我搜索了很多,但没有任何帮助。可能是因为我是新手..请帮助我
【问题讨论】:
-
使用他们的 auth.getcurentUser id 作为唯一键
-
得到唯一键后我该怎么办
-
也分享你的firebase数据库结构
-
你能分享一下你存储数据的代码吗?
-
使用 fcm id 作为父节点并在其中插入所有其他子节点。您将拥有单独的用户详细信息和节点
标签: android firebase firebase-realtime-database