Search code examples
androidkotlinservicekotlin-coroutines

Android timer service gets ignored


I have a service that constantly needs to update some data. For this, I'm using a foreground service with an indefinite loop (until the job is done). The issue is as soon as I leave the app, the service will "get ignored" and by this I mean the service will not get destroyed (I've put toasts there so I'm sure), however, the task is not executing and as soon as I open the app, the task executes again.


Solution

  • So the issue is not actually the service itself being in the foreground or the background( it should be in the foreground though but that's not resulting in the issue). But the issue is rather device-specific. Besides that as long as you run your service in foreground everything should work