I want my code to change a TextView
and change its content that can be seen for the following 5s. Then the activity has to finish.
firestore.collection("Game").document(gameID).addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot value, @Nullable FirebaseFirestoreException error) {
firestore.collection("Room").document(roomID).get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
if(documentSnapshot.getLong("inPlayers") == documentSnapshot.getLong("numPlayers")){
Intent in = new Intent(WaitingRoom.this, Game.class);
loadingView.setVisibility(View.GONE);
textoEsperando.setText("Starting...");
in.putExtra("roomID", roomID);
in.putExtra("gameID", gameID);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
startActivity(in);
finish();
}
}
});
}
});
That's my code. I've done it inside a EventListener
for changes in a document in Firestore. The problem is that first waits the 5s and then in the last moment apply the changes in the TextView and finishes. I don't know what's goin on to execute first the sleep and then the other parts of the code.