I'm trying to understand a particular bit of logic in IntentService
, specifically, in ServiceHandler
:
private final class ServiceHandler extends Handler {
public ServiceHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message msg) {
onHandleIntent((Intent)msg.obj);
stopSelf(msg.arg1);
}
}
From what I can tell, stopSelf()
is being called multiple times - once for every startService
call. If there are multiple items to handle, will stopSelf
not interrupt the flow of the pending items? Clearly that's not what's happening, since IntentService
actually works, but why? Seems like stopSelf
should be called after all the Intent
s are handled.
Another question - when will the HandlerThread
created in onCreate
actually stop? Clearly it's not halted by stopSelf
?