runOnUiThread 更新ui

来源:互联网 发布:java建立个人博客网站 编辑:程序博客网 时间:2024/06/05 17:50
/** * Runs the specified action on the UI thread. If the current thread is the UI * thread, then the action is executed immediately. If the current thread is * not the UI thread, the action is posted to the event queue of the UI thread. * * @param action the action to run on the UI thread */public final void runOnUiThread(Runnable action) {    if (Thread.currentThread() != mUiThread) {        mHandler.post(action);    } else {        action.run();    }}
在非ui thread中想要更新ui操作,需要使用runOnUiThread来完成。若当前线程是ui thread则立即执行,否则action 会被post到ui thread的event queue中。
原创粉丝点击