0
我想说明内螺纹Toast
消息..但我得到如何在线程内显示Toast消息?
RunTimeException:Can't create handler inside thread that has not called Looper.prepare()
请帮助我。提前致谢。
我想说明内螺纹Toast
消息..但我得到如何在线程内显示Toast消息?
RunTimeException:Can't create handler inside thread that has not called Looper.prepare()
请帮助我。提前致谢。
使用android.os.Handler
实例访问从另一个线程UI线程:
例如:
class YourUI exends Activity {
private Handler hm;
@override
public void onCreate(Bundle b) {
// do stuff, and instantiate the handler
hm = new Handler() {
public void handleMessage(Message m) {
// toast code
}
};
}
public Handler returnHandler(){
return hm;
}
}
在非UI线程中,使用:
YourUI.getHandler().sendEmptyMeassage(0);
尝试下面的代码在你的线程
runOnUiThread(new Runnable()
{
@Override
public void run()
{
//Your toast code here
}
});
会发生什么线程是一个非GUI线程,你不能从非GUI线程访问GUI元素
最好使用hm.sendEmptyMessage(0);在非UI线程:) – 2013-06-19 16:02:12
为我工作!谢谢!! (0);'to YourUI.returnHandler()。sendEmptyMeassage(0);'与您发布的代码一致。但完美的作品(+1) – Shudy 2013-07-04 09:14:49