Jeff Axelrod
Jeff Axelrod

Reputation: 28188

Android: Does an AlertDialog.show() start a new thread?

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.

Upvotes: 1

Views: 294

Answers (3)

Peter Knego
Peter Knego

Reputation: 80340

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

Upvotes: 0

Macarse
Macarse

Reputation: 93153

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

Upvotes: 2

Steve Bergamini
Steve Bergamini

Reputation: 14600

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.

Upvotes: 0

Related Questions