Properly handling the service foreground state