本文翻译自:Android basics: running code in the UI thread
In the viewpoint of running code in the UI thread, is there any difference between: 从在UI线程中运行代码的角度来看,之间有什么区别:
MainActivity.this.runOnUiThread(new Runnable() {
public void run() {
Log.d("UI thread", "I am the UI thread");
}
});
or 要么
MainActivity.this.myView.post(new Runnable() {
public void run() {
Log.d("UI thread", "I am the UI thread");
}
});
and 和
private class BackgroundTask extends AsyncTask<String, Void, Bitmap> {
protected void onPostExecute(Bitmap result) {
Log.d("UI thread", "I am the UI thread");
}
}
#1楼
参考:https://stackoom.com/question/ruuN/Android基础知识-在UI线程中运行代码
#2楼
None of those are precisely the same, though they will all have the same net effect. 这些都不是完全一样的,尽管它们都具有相同的净效应