线程UI更新报错:Only the original thread that created a view hierarchy can touch its views.

当我们在线程里面更新UI的时候会报错:Only the original thread that created a view hierarchy can touch its views.
如下面的代码:直接在UDP发送线程里面更新UI,就会报错,报错提示如下。
在这里插入图片描述
在这里插入图片描述
这里的解决办法是把UI更新放到Handler里面。所以把上述代码的UI更新部分修改为如下图所示。

在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章