First off, this is not aimed at perpetuating bloatware and other bad practices. I know many will say "don't do that" but I promise to respect users.
I am building an app where I would like a service to run indefinitely. A couple questions:
Are services listed in Advanced Task Killer? Or just Activities?
What's with the services that are always running (Settings -> Apps -> Running Services) like Skype, Swype, etc? I realize Skype could be a process with higher permissions than any Market apps (like packaged into kernel by Verizon or HTC), but Swype was something I installed (Beta for Incredible). So how does that manage to always run in the background? Furthermore - these items are not listed by Advanced Task Killer.
How does Pandora work. It keeps running even when you Task Kill it? Furthermore it's not re-launching itself because the music keeps playing smoothly.
Ideally I would like to build a Pandora-esque app where the users explicity hit the OFF button, but it will survive trigger happy task killers like myself. This would be a feature users are aware of / would agree to.
Wherever it can be avoided, this is not recommended. By default, it doesn't work, as Android gets more and more aggressive with each passing release about stopping this practice for non-foreground services (see below).
Swype is an input method editor. As such, even if something shuts it down, it will start up again shortly thereafter, to serve
EditText
widgets. I imagine that Android might not bother shutting down this service since it is reasonably likely to need it again in short order, but that's just a guess.Task killers were de-fanged on Android 2.2, so perhaps the problem is that the task killer simply is not working on your device.
Beyond that, you would have to ask the authors of Pandora, or Advanced Task Killer, neither of whom necessarily are monitoring StackOverflow.
Use
startForeground()
, to trade off Android not shutting you down (which otherwise will happen) with having aNotification
visible so the user remembers "oh, yes, I did agree to let this service run indefinitely, because it is constantly delivering value to me, rather than just being the product of some sloppy coder who couldn't be bothered to useAlarmManager
". Also, usually thatNotification
gives the user easy access to your aforementioned OFF button.