This is not a duplicated question, I now how to check if there is internet connection, what I don't know is how to pop dialog in while loop and try again until internet connection is back
I am trying to pop Alert dialog if there is no internet connection, and then wait for the user to hit "Try Again" when he hit the button, check the internet connection and pop again this Alert Dialog if there is no internet connection.
When I am doing this with if statement it works good - pop the dialog when there is no internet and check for connection when hit "Try Again" But, when I try to put this in a while loop the loop doesn't wait/show the dialog to the user.
What is the right way to do this? and why it is not working now?
while (netInfo == null || !netInfo.isConnected()) {
new AlertDialog.Builder(this)
.setTitle("title")
.setMessage("message")
.setPositiveButton("Try Again", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
netInfo = cm.getActiveNetworkInfo();
System.out.println("cm: "+cm+ " netinfo: "+ netInfo);
}
})
.show();
}