/** * 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 */ publicfinalvoidrunOnUiThread(Runnable action){ if (Thread.currentThread() != mUiThread) { mHandler.post(action); } else { action.run(); } }
View.post(Runnable r)方法。
boolean android.view.View .post(Runnable action)
//Causes the Runnable to be added to the message queue. The runnable will be //run on the user interface thread.