What's the difference between Activity.runOnUiThread(runnable action) and Handler.post()?

后端 未结 3 1273
终归单人心
终归单人心 2020-12-09 08:15

What\'s the differences/ advantages / drawbacks between using Activity.runOnUiThread or Handler.post(runnable action) in android ?

3条回答
  •  鱼传尺愫
    2020-12-09 08:37

    see here. if in UiThread, runOnUiThread() is called immediately, post() will be called after all the message handled. if not in other thread, runOnUiThread() is the same as post().

     public final void runOnUiThread(Runnable action) {
        if (Thread.currentThread() != mUiThread) {
            mHandler.post(action);
        } else {
            action.run();
        }
    }
    

提交回复
热议问题