- Only the original thread that cr
- Only the original thread that cr
- Only the original thread that cr
- Only the original thread that cr
- Only the original thread that cr
- 使用RecyclerView出现Only the origina
- 安卓Only the original thread that
- 从源码角度分析 - Activity.onCreate可以在子线
- Activity的生命周期 和 View的绘制流程 的关联
- only the original that created a
前言
在使用
Retrofit+OkHttp网络处理的时候,遇到如下错误
Only the original thread that created a view hierarchy can touch its views
翻译过来:只有创建这个View的线程才能操作这个View。就是没有在指定线程操作Ui。
解决方案一
在对应的回调接口根据网络请求返回的数据来传递不同的消息
handler.sendMessage(msg);
再根据消息的内容执行进一步操作
private Handler handler = new Handler()
{
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what)
{
case 1:
...
break;
}
}
};
解决方案二
MainActivity.this.runOnUiThread(new Runnable() {
public void run() {
// 目前已经处于Ui线程了
}
});








网友评论