view raw
pcdangio pcdangio - 7 months ago 50
Android Question

Android AlertDialog won't show until after bluetoothsocket.connect()

I have an

that is set to display before
, which is a blocking method. However, the
doesn't show until after the
method finishes.;
// Dialog is not shown.
mybluetoothsocket.connect(); // This blocks and takes a few seconds to run.
// Dialog is shown.

What could be causing this behavior?


If your bluetoothsocket.connect() is blocking, which you said it is, you should put it out of the UI main thread. What you can do is put it inside an AsyncTask. Your can be executed right before calling your AsyncTask. Then call myalertdialog.hide() in AsyncTask's onPostExecute().