Hacker News new | ask | show | jobs
by taneq 3632 days ago
Going offtopic from the rant to an Android development question, if I may - I thought background services were shut down brutally at random times, and hard to keep running reliably unless some app which uses them is open? I'm a newbie to Android dev, but I have an app which (attempts to) maintain an always-on connection, and I've gone with a foreground service because that doesn't get killed (as often).
1 comments

That seems to go against the documentation: (https://developer.android.com/guide/components/services.html)

> A started service must manage its own lifecycle. That is, the system does not stop or destroy the service unless it must recover system memory and the service continues to run after onStartCommand() returns.

A started service shouldn't be killed randomly - after all, that's how the downloads are handled - you don't see those disappearing without a reason.

Downloads are generally handled via foreground services (one significant difference is that foreground services show up as an icon in your notification area, notice downloads or Play Store updates appear there?). Background services are more like OLE in the sense of they let you set your app up so another app can ask it for stuff.