0

I am working on an application that runs a service. This service starts automatically when the system boots or the app is started. My manager asked me to check if it is still running periodically (eg. every 5 minutes) or each time the screen is turned off and then start the service again if not running.

The closest solution I found was this: http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/

This restarts the service only if the application is still running, which is unlikely if the user stopped it or killed it with some task manager.

Is it possible to have the service restarted other than boot-up or activity registered receiver? (Thinking about it as a User, I would not really like to have an application running all the time weather I wanted it or not.)

ZoltanT
  • 96
  • 1
  • 6

1 Answers1

0

Why do you need a watchdog on the service? If it's to prevent Android from recycling it to reclaim user resources, consider using the startForeground() method as discussed in this question: this requires you to have a notification icon for your service, providing an indication to the user. Listen to your own objection: avoid sneakiness towards the users!

Community
  • 1
  • 1
Pontus Gagge
  • 17,166
  • 1
  • 38
  • 51