As this page says:
Once started, a service can run in the background indefinitely, even
if the component that started it is destroyed.
So, if there’s an infinite loop in a service, and the system is low on resources, will the service be killed? If yes, so I can’t have sure that my service will run till the end?
yes your service can be killed by the OS if it needs the resources if you want to have something always run you need to use
startForegroundbut even that does not guarantee it wont be killed just a lot less likely.using
startForegroundrequires you to have a notification in the notification bar to tell the user that there is something running still