Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is the full body from <a href="http://developer.android.com/reference/android/app/Activity.html#runOnUiThread%28java.lang.Runnable%29">Activity.runOnUiThread(Runnable)</a>:</p> <pre><code>public final void runOnUiThread(Runnable action) { if (Thread.currentThread() != mUiThread) { mHandler.post(action); } else { action.run(); } } </code></pre> <p>The method body is still executed in your background thread, and mHandler of class <a href="http://developer.android.com/reference/android/os/Handler.html">android.os.Handler</a> implements an internal queue for Runnables posted to it, so unless you're doing blocking work in the Runnable (which is a <strong>big</strong> no-no on the UI Thread) or calling this method upwards of a thousand times in a short period, you should not see any difference.</p> <p>Now, if you were calling <a href="http://developer.android.com/reference/android/os/Handler.html#postAtFrontOfQueue%28java.lang.Runnable%29">Handler.postAtFrontOfQueue(Runnable)</a>, then there'd be an issue, because your Runnable is essentially "cutting in line". In this case, that would likely cause a stutter, because your Runnable is being executed instead of any UI updates that needed to take place (like scrolling). </p> <p>Note that you only <em>need</em> to run UI updates on the UI thread, like calling any methods on a View (thus the name "UI Thread" and why this method exists) or any operation where the documentation explicitly states that it needs to be run on the UI thread. Otherwise, if you're already on a background thread, there's no real reason to leave it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload