android 线程 弹出对话框
多线程,在线程中用handler实现弹出对话框
Handler handler = new Handler()
{
public void handleMessage(Message paramMessage)
{
comm.showDialog("添加成功!", ShopAddActivity.this);
}
};
new Thread(){
@Override
public void run()
{
handler.sendMessage(localMessage);
}.start();
要用handler,否则会报错Can't create handler inside thread that has not called Looper.prepare() 因为在Android中不能在子线程中来刷新UI线程,而可以在子线程中添加hander来发送消息更新线程。
多线程,在线程中用handler实现弹出对话框
Handler handler = new Handler()
{
public void handleMessage(Message paramMessage)
{
comm.showDialog("添加成功!", ShopAddActivity.this);
}
};
new Thread(){
@Override
public void run()
{
handler.sendMessage(localMessage);
}.start();
要用handler,否则会报错Can't create handler inside thread that has not called Looper.prepare() 因为在Android中不能在子线程中来刷新UI线程,而可以在子线程中添加hander来发送消息更新线程。
本文介绍如何在Android应用的子线程中通过Handler发送消息到主线程来显示对话框,避免因直接操作UI引发的错误。
3218

被折叠的 条评论
为什么被折叠?



