I'm using firebase in my app and most of the time it writes the values on the firebase entry with this instruction.
ref.setValue(result);
But on some rare occasions value is not written.
So I have thought about doing this:
boolean finished=false;
[...]
t=new Thread(new Runnable() {
@Override
public void run() {
while (!finished)
{
ref.setValue(result, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
finished=true;
}
}
});
t.sleep(50);
}
});
t.start();
As most of the time the data is written successfully, it looks like even if an error where to happen when wrting data, it would end up being written successfully anyway.
But maybe this is not enough to ensure that the data ends up being written and it may cause an infinite loop, getting one database error after another.
Is this a good approach to solve the problem?