在没有消息循环的情况下从另一个线程触发 Android 对话框
在 SurfaceView 中,我正在分派在标准“LockCanvas-Draw-unlockCanvasAndPost”循环中在画布上绘制的新线程。 (请注意,线程不包含消息循环)。
如何从该线程显示 Android 标准对话框?
由于线程没有消息循环,因此以下代码不起作用:
Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Alert");
builder.setMessage("Stackoverflow!");
builder.setNegativeButton("cancel", null);
builder.show();
In a SurfaceView, I'm dispatching new thread that draws on canvas within standard "LockCanvas-Draw-unlockCanvasAndPost" loop. (note that thread doesn't contains message loop).
How to show Android standard Dialog from that thread?
As thread doesn't have msg loop, following code doesn't work:
Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Alert");
builder.setMessage("Stackoverflow!");
builder.setNegativeButton("cancel", null);
builder.show();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以向第二个线程传递一个处理程序,您可以将消息发送到第一个线程,然后显示对话框。
You could pass the second thread a handler that you can send a message on to the first thread that will then show the dialog.