- 错误复现
在使用okhttp的时候新建了一个thread,在回调函数中创建了handler准备更新ui
- 错误原因
不能在子线程更新ui,需要回到主线程
- 解决办法
使用new Handler(Looper.getMainLooper());
- 代码样例
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
//更新ui操作
}
});