Only the original thread that created a view hierarchy can touch its views.

来源:互联网 发布:考试app软件 编辑:程序博客网 时间:2024/05/28 01:34

在Android 77.0的系统中,在子线程更新UI界面会产生如下异常:

android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views:

可以使用Handler等工具将更新信息发送到主界面,然后通过主界面来更新消息即可,亦可通过如下方法来避免:

runOnUiThread(new Runnable() {                    @Override                    public void run() {                      //更新UI消息                    }                });
0 0
原创粉丝点击