I just need to do a little bit of sanity check here. Let's say I have a service that's run periodically. If the app is in the foreground (and screen is on, etc), would there ever be a reason to use Service.StartForeground?
(I do realize I need to use it if the app is in background, just curious of when app is in foreground.)
(just thinking) You know that the app is in Foreground when the Service is called but can't tell if it will be Paused for whatever reason just after starting this service.
Perhaps it is only an edge case and is not likely to happen, but if the service task can last a bit (connect to server...) and the Activity has been paused, it could be killed
So you're saying the correct strategy is to StartForeground it, regardless if the app is in foreground or background - as a way to minimize potential problems that might be caused by end user doing something while service is running?
So you're saying the correct strategy is to StartForeground it, regardless if the app is in foreground or background - as a way to minimize potential problems that might be caused by end user doing something while service is running?
Another one: Android/Google wants the user to be noticed if a service is running (and not doing "bad" things in the background). So the standard behaviour on the newest Android versions is to start it in foreground (except services where you stop it e.g. firebase messaging - it is then started by the OS via intent - which is ok)