Dialogs / AlertDialogs: How to block execution while dialog is up (.NET-style)
Ted, you don't want to do this, really :) The biggest reason is that if you block the UI thread while you are displaying a Dialog, you will block the thread that's in charge of drawing and handling the events of your Dialog. Which means your dialog will be unresponsive. You will also cause ANRs if the user takes more than a few seconds to click the dialog.
Erich's answer is exactly what you need. I know it's not what you want, but that doesn't matter. We've designed Android to prevent developers from writing synchronous dialogs so you don't really have much of a choice.
modal dialog in Android
I believe you will find your answer here
Dialogs / AlertDialogs: How to "block execution" while dialog is up (.NET-style)
In general you should not be blocking the code while a dialog is visible, your logic should be different and fit android way of doing things.
Is a Dialog asynchronous on Android?
That line of code:
alert.show();
tells the system to asynchronously show the alert at the next 'tick' of the UI thread, and therefore all code afterwards is executed first.
The UI thread has a message Looper that is handling messages sequentially. Your onCreate() function is being executed because the looper is handling the messages that are a part of the application start up. The onCreate() function must first finish executing before the looper can loop back to the next message which will be the 'make the alert dialog visible' message that was put on the message queue by the call to show()
.
DialogResult in normal java class and return result
After many hours hunting through the inner depths of google pages, I found this Dialogs / AlertDialogs: How to "block execution" while dialog is up (.NET-style).
It does exactly the job I was after and tested to make sure there are no ANR errors, which there isn't
Related Topics
Android Device Not Shown with Adb
How to Launch Termux Through Another Android App
Android Failed to Start Emulator:Cannot Run Program
How to Remove Strings from a Compiled Binary (.So)
How to Integrate Opencv into Qt Creator Android Project
Passing Data from Java Class to Web View HTML
Android Webview Err_Unknown_Url_Scheme
Media Queries Not Behaving as Expected on Android
Android - Multiple Screen Support Issue
What Does Porterduff.Mode Mean in Android Graphics.What Does It Do
Why Does Contentresolver.Requestsync Not Trigger a Sync
What Is the Size of Actionbar in Pixels
Jelly Bean Datepickerdialog --- How to Cancel
Android Webview - Webpage Should Fit the Device Screen
Design Android Edittext to Show Error Message as Described by Google