Java Show a Messagebox for a short time and make it disappear by itself
<p>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. </p>

<p>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</p>

<p>Would be great, if someone could look into it. Thanks in advance.</p>

<p>Here is the code:</p>

<pre><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&lt;100) {
        alertDialog.show();
        i++;
    }

//            alertDialog.dismiss();


        screenrefresh();
        handler();
</code></pre>