A Handler
is attached to the thread it was created on.
handler.post(Runnable)
can be used to run code on the thread Handler is attached to.
Activity.runOnUIThread(Runnable)
always run the given runnable on the activity's UIThread. Internnaly it does so through a handler Activity creates when constructed like so:
final Handler mHandler = new Handler();
Hence runonUiThrad code looks like this:
public final void More ...runOnUiThread(Runnable action) {
if (Thread.currentThread() != mUiThread) {
mHandler.post(action);
} else {
action.run();
}
}
As you can see if the current thread is not the UI thread, it posts the given runnable on its member handler which we referred to earlier.
If the caller is already on the ui thread, it just calls the runnable.
Rad the code here.