I have a problem with the Firebase in Android Studio.
I have 2 buttons on my interface, one that is called "Upload Data" and another one called "Get Data". When I click on the "Upload Data" button, it uploads the data perfectly to the Firebase, however, when I click on the "Get Data" button, I program it to generate a PDF report of all the Firebase information, and the first time I hit the "Get Data" button if it gives me what I want, but when I hit the "Upload Data" button again it uploads the information to the Firebase, then updates the Firebase and inadvertently shows me the previously created PDF (THIS IS MY PROBLEM), it makes sense, since the Firebase was updated and therefore must show the PDF since its code is inside:
"ValueEventListener listener = new ValueEventListener() { @Override
public void onDataChange(DataSnapshot dataSnapshot) {"
This code is inside the "GetData" button.
What can I do?
Thanks:)
public void boton3_basededato(View view){
templatePDF.openDocument();
templatePDF.addParagraph(shortText);
templatePDF.addParagraph(longText);
DatabaseReference mRootReference;
mRootReference = FirebaseDatabase.getInstance().getReference();
mRootReference.child("Usuario").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
int cont=0;
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
String todo=snapshot.getValue().toString();
if(todo.contains("{")){cont++;}
}
int j=0;
for (DataSnapshot snapshot : dataSnapshot.getChildren()) { //lo que esta despues de los ":" obtiene los datos alfanumericos y el snapshot.getValue obtiene los demas valores que estan dentro
userPojo user = snapshot.getValue(userPojo.class); // que me traiga los valores que solo estan declarados en el userPojo.class
templatePDF.addParagraph(user.getCodigo());
templatePDF.addParagraph(user.getPlano());
templatePDF.addParagraph(user.getElemento());
templatePDF.addParagraph(String.valueOf(user.getSlump()));
templatePDF.addParagraph(user.getComentario());
templatePDF.addParagraph(espacios);
j++;
if(j==cont){
templatePDF.closeDocument();
templatePDF.viewBasededatos();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}