Android:AlertDialog.show() 是否启动一个新线程?
AlertDialog.show()
是否启动一个新线程?我在 Android 文档中没有看到任何迹象表明它确实如此,并且希望得到确认。
具体来说,我想确保 OnDismiss()
回调发生在 UI 线程上。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简而言之:不,它不会创建新线程,是的,它在 ui 线程中运行。
Long:它应该在 ui 线程中运行,因为它会修改 ui 内容,但您可以从另一个线程创建它,并且最终会出现异常。如果您有第二个线程,您应该使用与 ui 线程通信的不同方式之一从 ui 线程执行所有
AlertDialog
调用。例如runOnUiThread
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 instancerunOnUiThread
不会。AlertDialog 在当前 Activity 线程上启动。您想要在后台执行的任何操作都需要在单独的线程(Thread、AsyncTask 等)上完成。当关闭对话框时,您确实需要从 Activity 线程中调用关闭。
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.
据我所知,事实并非如此。没有理由会这样。但为了确保你可以检查源代码。
AFAIK it does not. There is no reason why it would. But to be sure you can inspect the source code.