【发布时间】:2013-04-19 19:19:19
【问题描述】:
尝试在服务中调用异步任务的构造函数时遇到问题。
我收到了这个错误
Can't create handler inside thread that has not called Looper.prepare().
我应该在 UIThread 中调用 AsyncTask 吗?
奇怪的是,它在 Jellybean 中工作,但在 ICS 中崩溃。
@Override
public void onCreate(){
super.onCreate();
WebRequest wr = new WebRequest(this.serviceURL, this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
wr.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, processType, newMap);
else
wr.execute(processType, newMap);
}
【问题讨论】:
-
你能提供更多代码吗?看来您的代码是正确的。
标签: java android multithreading android-asynctask android-service