No Service.StopAutomaticForeground say to android that app's service is complete and stop foreground service
Sleep is short interrupt for force Service.StopAutomaticForeground and it is good use it
Ok, Sleep(0) pauses the service... and allows a call for a sub in service to start, registering that the service hasn't finished yet. If you call StopAutomaticForeground before sleep(0) maybe there is no chance to run a sub called by an intent , push service or callsubdelayed, before the service be stopped.
But the doubt about http service remains.. remember that httpjob runs in other thread. then, for main thread of app when a service calls httpjob it's done and finished... that's because the jobdone callback runs the Service_Start again... but if StopAutomaticForeground doesn't detect that httpjob is still running in other thread, we could have one of the behaviors:
1. Service is destroyed after StopAutomaticForeground and is created again by httpjob callback... this isn't good because if the routine that calls httpjob is in the create section, we will have an eternal and dangerous loop...
or
2. When http job callback raises, it's generated an error because the service is destroyed and the jobdone routine doesn't run....
The only reasonable situation is to detect that the service is still waiting for jobdone and remains running until finish the jobdone routine... of course that to do this StopAutomaticForeground must to detect that there is an external call being waited for a service subroutine and only stops the service after the callback target routine runs (when working with multi threaded systems we use to do this with semaphores and flags...) .
The question: is this behavior implemented in StopAutomaticForegorund call?