pcdangio pcdangio - 1 year ago 73
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?

Answer Source

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 myalertdialog.show() can be executed right before calling your AsyncTask. Then call myalertdialog.hide() in AsyncTask's onPostExecute().