在android開發中,遇到這個問題:
Can't create handler inside thread that has not called Looper.prepare()
問題原因:
在android的多線程開發中,比如asyncTask,在其doInBackground()方法,調用了更新UI的方法。
解決辦法:
把更新UI的操作,放到消息處理器中處理;在doInBackground()方法中發送更新消息:
Handler updateDate = new Handler(){
@Override
public void handleMessage(Message msg) {
switch(msg.what){
case LOADING_FINISHED:
listView.setAdapter(gameAdapter);
break;
}
}
};