android: toast报错 :Can't toast on a thread that has not called Looper.prepare()
一,报错信息:
java.lang.RuntimeException: Can't toast on a thread that has not called Looper.prepare()
原因:
原因是Android中不允许在子线程中处理UI。
如果要在子线程中处理UI那就要动态转到主线程中执行,
解决方法:使用Looper
二,解决:
代码如下:
Looper.prepare();
Toast.makeText(context, "消息内容:状态正常", Toast.LENGTH_SHORT).show();
Looper.loop();
代码前后分别添加了:
Looper.prepare();
和
Looper.loop();