I am using the following code to show an AlertDialog and prompt the user to press "Retry". The dialog should remain on-screen until connection is available. The app works correctly in that when network is unavailable the dialog appears.
mProgressBar = new ProgressBar(MainGroupActivity.this);
AlertDialog.Builder builder = new AlertDialog.Builder(MainGroupActivity.this);
builder.setTitle("Not Connected")
.setIcon(R.drawable.disconnect)
.setView(mProgressBar)
.setMessage("You are not connected to the Internet")
.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//Retry connection
if(isNetworkAvailable ())
mDialog.dismiss();
}
});
mDialog = builder.create();
if( !isNetworkAvailable() )
mDialog.show();
The problem is that the dialog is dismissed as soon as I touch somewhere on the screen or press Retry! How can I prevent that?