I’m trying to implement AsyncTask in my application. Problem is that it was created and executed from different thread, so I got exception. I moved forward and implement small runnable that will create and execute my AsyncTask. I run this runnable in runOnUIThread() method, but still got this error in my runnable’s constructor, on line with AsyncTask constructor:
Can't create handler inside thread that has not called `Looper.prepare()`
Any ideas what to do?
Need code?
myLocationOverlay.runOnFirstFix(new Runnable() {
@Override
public void run() {
fillMap();
}
});
public void fillMap(){
runOnUiThread(new AsyncTaskRunner());
}
private class AsyncTaskRunner implements Runnable {
DownloadDataTask task;
public AsyncTaskRunner(double latitude, double longitude, int radius) {
super();
this.task = new DownloadDataTask(latitude, longitude, radius);
}
@Override
public void run() {
task.execute();
}
}
The constructor of the AsyncTask is still being called on the non-UI thread. Can you move the construction of the AsyncTask to run method?