【发布时间】:2012-10-02 17:48:57
【问题描述】:
从在UI线程中运行代码的观点来看,两者有什么区别:
MainActivity.this.runOnUiThread(new Runnable() {
public void run() {
Log.d("UI thread", "I am the UI thread");
}
});
或
MainActivity.this.myView.post(new Runnable() {
public void run() {
Log.d("UI thread", "I am the UI thread");
}
});
和
private class BackgroundTask extends AsyncTask<String, Void, Bitmap> {
protected void onPostExecute(Bitmap result) {
Log.d("UI thread", "I am the UI thread");
}
}
【问题讨论】:
-
澄清我的问题:我认为这些代码是从服务线程调用的,通常是侦听器。我还认为在 AsynkTask 的 doInBackground() 函数中或在前两个 sn-p 之前调用的 new Task(...) 中需要完成繁重的工作。无论如何,AsyncTask 的 onPostExecute() 被放在事件队列的末尾,对吧?
标签: android android-asynctask android-view android-ui