android的子线程切换到主线程

在子线程中,如果想更新UI,必须切换到主线程,方法如下:

if (Looper.myLooper() != Looper.getMainLooper()) {
                // If we finish marking off of the main thread, we need to
                // actually do it on the main thread to ensure correct ordering.
                Handler mainThread = new Handler(Looper.getMainLooper());
                mainThread.post(new Runnable() {
                    @Override
                    public void run() {
                        mEventLog.add(tag, threadId);
                        mEventLog.finish(this.toString());
                    }
                });
                return;
            }

  

posted @ 2019-05-23 17:07  明明一颗大白菜  阅读(5660)  评论(0编辑  收藏  举报
<-- -->