I'm trying to authanticate users with email and password and I want to add two extra fields (name and kredi) when someone going to sign-up. But when I sign-up to my app, two more fields with "user" tag saving to firebase realtime database like this:
wohR9lJXnMgj9zCYMaasZDctrhf1
kredi:
"20"
name:
"test"
userKredi:
"20"
userName:
"test"
I don't understand why this is happening. This is my sign-up activity code:
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class SignUpActivity extends AppCompatActivity {
EditText signUpMail,signUpPass,kullaniciAdi;
Button signUpButton;
private FirebaseAuth auth;
private DatabaseReference databaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
auth=FirebaseAuth.getInstance();
signUpMail = findViewById(R.id.signUpMail);
signUpPass = findViewById(R.id.signUpPass);
kullaniciAdi = findViewById(R.id.kullaniciAdi);
auth=FirebaseAuth.getInstance();
signUpButton = findViewById(R.id.signUpButton);
signUpButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
signUp();
}
});
}
private void signUp() {
final String email = signUpMail.getText().toString().trim();
final String pass = signUpPass.getText().toString().trim();
final String kredi = "20";
final String name = kullaniciAdi.getText().toString().trim();
if(TextUtils.isEmpty(email)){
Toast.makeText(getApplicationContext(),"Please enter your E-mail address",Toast.LENGTH_LONG).show();
return;
}
if(TextUtils.isEmpty(pass)){
Toast.makeText(getApplicationContext(),"Please enter your Password",Toast.LENGTH_LONG).show();
}
if (pass.length() == 0){
Toast.makeText(getApplicationContext(),"Please enter your Password",Toast.LENGTH_LONG).show();
}
if (pass.length()<8){
Toast.makeText(getApplicationContext(),"Password must be more than 8 digit",Toast.LENGTH_LONG).show();
}
else{
auth.createUserWithEmailAndPassword(email,pass)
.addOnCompleteListener(SignUpActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Userinformation userinformation = new Userinformation(
name,
kredi
);
databaseReference = FirebaseDatabase.getInstance().getReference();
databaseReference.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(userinformation).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
startActivity(new Intent(SignUpActivity.this, HomeActivity.class));
finish();
}
else{
Toast.makeText(SignUpActivity.this, task.getException().getMessage(),Toast.LENGTH_LONG).show();
}
}
});
}
else {
Toast.makeText(SignUpActivity.this, task.getException().getMessage(),Toast.LENGTH_LONG).show();
}
}
});
}
}
public void navigate_sign_in(View v){
Intent inent = new Intent(this, SignInActivity.class);
startActivity(inent);
}
}
and Userinformation class:
public class Userinformation {
public String name;
public String kredi;
public Userinformation(){
}
public Userinformation(String name,String kredi){
this.name = name;
this.kredi = kredi;
}
public String getUserName() {
return name;
}
public String getUserKredi() {
return kredi;
}
}
I just want to save those properties just once. How can I do this?
The problem is at your pojo, change this
public String getUserName() {
return name;
}
public String getUserKredi() {
return kredi;
}
to this
public String getName() {
return name;
}
public String getKredi() {
return kredi;
}
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.