从在UI线程中运行代码的角度来看,之间有什么区别:
MainActivity.this.runOnUiThread(new Runnable() {
public void run() {
Log.d("UI thread", "I am the UI thread");
}
});
Run Code Online (Sandbox Code Playgroud)
要么
MainActivity.this.myView.post(new Runnable() {
public void run() {
Log.d("UI thread", "I am the UI thread");
}
});
Run Code Online (Sandbox Code Playgroud)
和
private class BackgroundTask extends AsyncTask<String, Void, Bitmap> {
protected void onPostExecute(Bitmap result) {
Log.d("UI thread", "I am the UI thread");
}
}
Run Code Online (Sandbox Code Playgroud) 有人可以向我解释一下UI线程到底是什么吗?在developer.android.com上,它说的是runOnUiThread函数
public final void runOnUiThread(Runnable action)
从以下版本开始:API Level 1在UI线程上运行指定的操作.如果当前线程是UI线程,则立即执行该操作.如果当前线程不是UI线程,则将操作发布到UI线程的事件队列.
UI线程是否意味着每次通过某些ui活动(如来电或屏幕调暗等)将活动推送到后台时都会运行此线程?如果没有,UI线程到底包含什么?
谢谢