1

Any application that has a service going obviousely counts on it to be always running. It's part of the product and if it's a paid app - the user expects it.

However, it seems that there is no way for a service not to get wacked if the Android OS feels the memory pressure or if something goes wrong and the service crashes.

What is the best way of making sure that a service is always running?

Is it wise to create a second service that once in a while start the "useful" service and if it's alredy running it'll be ignored?

dsolimano
  • 8,870
  • 3
  • 48
  • 63
kidalex
  • 1,437
  • 2
  • 12
  • 14
  • 2
    Don't do this. You'll just get killed by a task killer, and your users shouldn't have to kill your service. Use an AlarmManager instead. – Falmarri Feb 05 '11 at 10:08

2 Answers2

3

To be honest, I am not sure if this is a good idea as all.

If there is enough memory pressure, it would not be fair towards other apps to insist on running. Also services only get kicked out on severe low memory situations.

If you write a reaper service, this one can get kicked out too.

And as you say " and if it's a paid app - the user expects it." -- the user also expects that apps play nicely

Heiko Rupp
  • 30,426
  • 13
  • 82
  • 119
1

If your service is 'critical', you can use startForeground which gives your service as much priority as an Activity in the foreground.

Chris Banes
  • 31,763
  • 16
  • 59
  • 50
  • I just re-wrote my code using the AlarmManager and IntentService but it seems that every time my app runs and the alarm is registered it trips over its own instance that's already running and dies. The alarm stops executing every hour as well so what's the point anyway? – kidalex Feb 05 '11 at 12:30