after reading a lot of solutions on AlertDialog I finally managed to get a message displayed. The message is the counter for the rounds in a little game. The Message should pop up, before the player enters the next round. It should remain a few seconds and then disappear by itself.
What happens: The programm gets stuck in showing the alert window and does not go to the i++ line. Any idea how to solve this problem without introducing a button that the user must hit? I have taken out the dismiss() because there is a screenrefresh afterwards anyway. But at the moment it woudn't reach that point anyway. I am working with Android Studio 2.2.2
Would be great, if someone could look into it. Thanks in advance.
Here is the code:
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.Date;
import java.util.Random;
private void startRound() {
int i=0;
round = round +1;
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(" ");
alertDialog.setMessage("Round " + round);
while(i<100) {
alertDialog.show();
i++;
}
// alertDialog.dismiss();
screenrefresh();
handler();
You should show your dialog and use handler to dismiss :
If you refresh activity you can use Toasts .
you can customize your toast style .