Android alertdialog not showing when I think it should <p>I'm developing an android app which I want to check if there's internet connection, if it's not the case display a warning message, and when there's internet connection again load a certain url.</p> <p>It can be said that both displaying the message and checking there's internet connection work... but no separately.</p> <p>I mean I have the following code:</p> <pre><code> if (!checkConnectivity()) { browser.stopLoading(); LayoutInflater layoutinflater = LayoutInflater.from(app); final View textEntryView; textEntryView = layoutinflater.inflate(R.layout.exitdialog, null); new AlertDialog.Builder(app) .setView(textEntryView) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle("Exit") .setNegativeButton("CANCEL", null) .show(); while (!checkConnectivity()) { } browser.loadUrl(url); } </code></pre> <p>If I don't use from while (!checkConnectivity()) to browser.loadUrl(url); then AlertDialog shows properly.</p> <p>If I don't use from LayoutInflater layoutinflater = LayoutInflater.from(app); to .show(); then the app loads the web page correctly on browser.</p> <p>But if I use the whole code it looks like it enters the while (!checkConnectivity()) loop before it does the show as what happens when internet connection is restabilished is that the alert dialog is shown briefly and the the web page is loaded.</p> <p>I find this pretty weird, as I'm not using, as far as I know, threads that could cause that one could be executed before other one, and this is not the case this thing doesn't fulfill one of the most basic things in programming, I mean if an instruction is before another one, the one that's before should be plenty executed logically (except for threads).</p> <p>Hope someone has an idea about this and can help me.</p>