子线程中不能创建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.