I would like to pause my android app for 1 second after I inserted something into the Firebase database. For that I use the following code insider a liistener:
firebase_DB.child(id).setValue(currentOrder).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
orderSuccesfullyWritten[0] =true;
orderCouldNotBeSendAfterMutipleAttemps[0] = false;
Log.e("dbTAG", "Data successfully written.");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
Log.e("dbTAG", task.getException().getMessage());
}
}
});
The code is being executed (and I get the message that "Data successfully written" but the Threas.sleep(1000)
does not have any effects. The app just directly continues with the next actions. Any idea why this is the case? I'll appreciate every comment.