当前位置: 代码迷 >> Android >> 子线程中不能创造AlertDialog
  详细解决方案

子线程中不能创造AlertDialog

热度:23   发布时间:2016-04-28 07:59:39.0
子线程中不能创建AlertDialog
如题:我new了一个线程,在run函数里面创建一个AlertDialog,报了这个错
java.lang.RuntimeException: Can't create headler inside thread that has not called Looper.prepare().
这是什么意思啊?求大神解答。
AlertDialog 线程 thread

------解决方案--------------------
在run内部第一行就加上
Looper.prepare();
------解决方案--------------------
对话框只能由主线程显示,从线程中调用的方法是:
1  在主线程中 new 一个 handler,
2  在子线程中将数据发送 postMessage 或 sendMessage 到上 handler 中,在那里再显示 alertdialog.
  相关解决方案