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 回答
![?](http://img1.sycdn.imooc.com/545868c20001b8c402200220-100-100.jpg)
倚天杖
TA贡献1828条经验 获得超3个赞
runOnUiThread()
Runnable
post()
Runnable
BackgroundTask
doInBackground()
post()
AsyncTask
onPostExecute()
.
![?](http://img1.sycdn.imooc.com/533e4d510001c2ad02000200-100-100.jpg)
杨魅力
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 关注
- 1062 浏览
添加回答
举报
0/150
提交
取消