This is the full body from Activity.runOnUiThread (Runnable) :
public final void runOnUiThread(Runnable action) { if (Thread.currentThread() != mUiThread) { mHandler.post(action); } else { action.run(); } }
The body of the method is still running in the background thread, and the mHandler of the android.os.Handler class implements an internal queue for Runnables sent to it, so if you arenβt "Performing blocking work in Runnable (which is a big no-no in the user interface thread) or calls this method more than a thousand times in a short period, you will not see any difference.
Now, if you called Handler.postAtFrontOfQueue (Runnable) , then there would be a problem, because your Runnable is essentially a "slice". In this case, it can cause a stutter because your Runnable is being executed instead of any user interface updates that should have been performed (e.g. scrolling).
Please note that you only need to run UI updates in the UI thread, for example, call any methods in the view (thus the name "UI thread" and why this method exists) or any operation that is explicitly stated in the documentation that it should be executed in the user interface thread. Otherwise, if you are already in the background thread, there is no real reason to leave it.
source share