Android基礎:在UI線程中運行代碼從在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");
}}
3 回答

倚天杖
TA貢獻1828條經驗 獲得超3個贊
runOnUiThread()
Runnable
post()
Runnable
BackgroundTask
doInBackground()
post()
AsyncTask
onPostExecute()
.

楊魅力
TA貢獻1811條經驗 獲得超6個贊
它可以在沒有任何參數的情況下在任何地方使用:
new?Handler(Looper.getMainLooper()).post(new?Runnable()?{ ????@Override ????public?void?run()?{ ????????Log.d("UI?thread",?"I?am?the?UI?thread"); ????}});
- 3 回答
- 0 關注
- 1085 瀏覽
添加回答
舉報
0/150
提交
取消