I have a queue of Jobs which execute sequentially - the onRun() of each job looks like this:
@Override
public void onRun() throws Throwable {
if (Looper.myLooper() == null) {
Looper.prepare();
}
this.looper = Looper.myLooper();
makeQuery(looper);
Looper.loop();
}
the makeQuery() function does a database call that runs on a background thread that reports back to this job by posting a Runnable to a handler for this thread. Like so:
{
// ... make a query in another thread...
Handler handler = new Handler(looper);
handler.post(new Runnable() {...});
}
And when the result of the query is received, it does something then calls:
this.looper.quit();
So far so good - the first job on the queue executes fine, but the 2nd job gets as far as executing the query and then the code above that tries to post the result - handler.post - fails with this exception:
"sending message to a Handler on a dead thread"
One thing I noticed is that the 2nd job is running on the same thread as the first, so the JobManager is reusing it, given that it has been configured for FIFO operation, I guess that is efficient. However, why is the thread in the state 'Quitting' when the second job runs on it that is causing this process to barf?