Concurrency issue with Android Looper / Handler -


i have queue of jobs execute sequentially - onrun() of each job looks this:

    @override     public void onrun() throws throwable {         if (looper.mylooper() == null) {             looper.prepare();         }         this.looper = looper.mylooper();         makequery(looper);         looper.loop();     } 

the makequery() function database call runs on background thread reports job posting runnable handler thread. so:

{     // ... make query in thread...     handler handler = new handler(looper);     handler.post(new runnable() {...}); } 

and when result of query received, calls:

this.looper.quit(); 

so far - first job on queue executes fine, 2nd job gets far executing query , code above tries post result - handler.post - fails exception:

"sending message handler on dead thread"

one thing noticed 2nd job running on same thread first, jobmanager reusing it, given has been configured fifo operation, guess efficient. however, why thread in state 'quitting' when second job runs on causing process barf?


Comments