I hace attached my device to the PC and run my service via Eclipse on the device. Now I would like to see what is the behavior of my service over power-off and power-on. The problem is that once O power-off the device my service is lost. Is it possible to keep the application persistent on the device over power-off?
Thanks.
Your service will not run when the device is powered off - because well there is not power. But you can make the service available as soon as power is provided to the device. Make sure your service is efficient so it is not killed when memory is getting tight. Then just use a broadcast receiver to catch there
<action android:name="android.intent.action.BOOT_COMPLETED"/>
intent. From the receiver you can send and intent to launch your service. You could also use this intent in your service's Intent Filter to start the service. Use the PowerManager with a partial wake lock to help your service run when the screen is off - But note: This feature does not work on all devices - Of all the devices I have used this feature works on half, but not perfect.
If you want to help your service from not being killed by the OS even more - run it as a foreground service using the startForeground() API call in the service object.