I'd like to create an AsyncTask that sits in the background and calls a web service every X seconds.
private class BackgroundTask extends AsyncTask<Integer, Integer, Boolean> {
protected Boolean doInBackground(Integer... params) {
if (params.length > 0) {
int intUserId = params[0];
if (intUserId != -1) {
boolean blnRunning = true;
while (blnRunning) {
// perform query
try {
this.wait(15000);
}
catch (InterruptedException e) {
blnRunning = false;
}
}
}
}
return false;
}
protected void onPostExecute(Boolean blnLaunchStoreFavorites) {
// do something?
}
}
This is what I have.
Shortly after this.wait() is called, I get an error down in the bowels of ThreadPoolExecuter.class.
Uncaught handler: thread AsyncTask #2 exiting due to uncaught exception
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1096)
I'm not quite sure what is going on here. Any ideas?