0
Does anyone know how to input data into the Firebase Realtime database? My application does not give errors but does not insert anything in Firebase.
Note: Database and application are connected and synchronized.
in Firebase, my database is search-inc. I want to create a data tree, like:
buscacerto-inc
|___users
|___id
| |____Nome
| |____cpf
| |____email
|
|___id
|____Nome
|____cpf
|____email
My code is this:
try{
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference refer = database.getReference("buscacerto-inc/users");
Usuario usuario = new Usuario(email, senha); //Minha classe Usuario
refer.push().setValue(usuario.pegaEmail(), usuario.pegaSenha());
Toast.makeText(actCadastro.this, "Usuário cadastrado com sucesso!!!", Toast.LENGTH_SHORT).show();
}catch (Exception ex){
Toast.makeText(actCadastro.this, "Erro: " + ex.getMessage(), Toast.LENGTH_SHORT).show();
}
As I said, it does not generate errors and seems to access Firebase without problems. I am using public Getters (user.pegaEmail) to not leave the Class fields exposed. I pushed() because I want to create a unique id for each one.
You don’t need to put "solved" in the title. I know it’s common practice in many forums, but here it’s different. You have already marked a reply below with and this is enough to indicate that it has been solved.
– hkotsubo