// A instance of Activity
....
.
runOnUiThread(new Runnable() {
public void run()
{
TextView textBox= (TextView)getViewById(R.id.textbox);
textBox.setText(R.string.login_failed);
}
....
.
runOnUiThread(new Runnable() {
public void run()
{
TextView textBox= (TextView)getViewById(R.id.textbox);
textBox.setText(R.string.login_failed);
}
});
内部实现其实就是调用的hander.post();
// Reference from Activity.java
/**
* 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
*/
public final void runOnUiThread(Runnable action) {
if (Thread.currentThread() != mUiThread) {
mHandler.post(action);
} else {
action.run();
}
}