0
I’m a beginner on Android and had a problem recovering data from Firebase and record again, I know the reason for the infinite loop but I don’t know how to fix.
public static void setVoto (String candidato){
votoFirebase = referenciaDatabase.child(candidato).child("votos");
votoFirebase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
voto = dataSnapshot.getValue().toString();
votoInt = Integer.parseInt(voto);
votoFirebase.setValue(votoInt + 1);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
The problem happens that whenever the value is changed, it goes back to the method, so when the person votes, it gets in an infinite loop.. How can I fix, or use another function so I can recover the current firebase score and record the data by adding +1 without the loop ? I tried to create a flag, it worked, however when the app is closed and open, the flag returns as true and allows the user to vote again...
Thank you very much, it worked
– Felipe Pacheco Paulucio