I am currently starting to use firebase
and I want to implement a database in my Android
app, I am trying to upload two Objects, for now I have uploaded a Person type Object in the following way:
in OnCreate
:
mFirebaseDatabase = FirebaseDatabase.getInstance();
mDataBaseReference = .
mFirebaseDatabase.getReference().child("Personas");
Then to add my object to the database:
mClientesDataBaseReference.push().setValue(nuevaPersona);
Achieving upload this:
personas : {
"dsgasdgjbnakjds" : {
"Nombre" : "Lalo",
"FotoId" : "1",
"edad" : "18",
}
}
My object is something like this:
public Cliente(){
//Variables de tipo String
nombre = "";
FotoId = "";
Edad = "";
// Variable tipo Mascota
mastoca = new Mascota();
}
public Mascota{
//String
Nombre = "";
Edad= "";
}
However, even declaring the pet as part of the Persona
object, it does not appear in the database.
I would like to be able to add the Object ( mascota
) within this same Object of persona
and achieve something similar to this:
personas : {
"lksdjnflkasdg" : {
"Nombre" : "Lalo",
"FotoId" : "1",
"edad" : "18",
"Mascota" : {
"nombreMascota" : "LittleDog",
"edadMascota" : 3
}
},
"lkjndslfknlksdn" : {
"Nombre" : "Roberto",
"FotoId" : "2",
"edad" : "20",
"Mascota" : {
"nombreMascota" : "LittleDog",
"edadMascota" : 5
}
}
Thanks