1

Does an AlertDialog.show() start a new thread? I don't see any indication in the Android documentation that it does, and would like confirmation.

Specifically, I want to make sure that the OnDismiss() callback occurs on the UI thread.

Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246

3 Answers3

2

Short: No, it doesn't create a new thread and yes it runs in the ui thread.

Long: It should be running in the ui thread since it modifies ui stuff but you can create it from another thread and you will end having an exception. If you have a second thread you should do all the AlertDialog calls from the ui thread using one of the different ways to communicating with the ui thread. For instance runOnUiThread

Macarse
  • 91,829
  • 44
  • 175
  • 230
0

No. The AlertDialog is kicked off on the current Activity thread. Anything you want to do in the background would need to be done on a seperate thread ( Thread, AsyncTask, etc.). When dismissing the dialog, you indeed need to call the dismiss from the Activity thread.

SBerg413
  • 14,515
  • 6
  • 62
  • 88
0

AFAIK it does not. There is no reason why it would. But to be sure you can inspect the source code.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154