Search code examples
androidandroid-wake-locksleep-modeandroid-powermanager

Service goes to standby when device sleeps - Android


Envrionment: Eclipse
Language: Java (Android)

I have a bit of a problem, which I didn't realise until I tested my application out on a device. I always thought that services would continuously be running in the background, even when the phone's sleeping. I found out that this is not the case, so, my question is that does the service start up again once you wake your device up? And if not, how would I cause the service to start-up again.

Would I be able to wake the phone every 5 minutes or so, just to run my service, which will last 30 seconds to 1 minute. And then make the phone sleep again?

Thanks in advance.

EDIT: I am very new to Android programming and would really appreciate if someone would tell me how to use WakefulIntentService. I have a service that is searching for the user's GPS Location every so often, and when the phone goes to sleep, I want my service to still look for their location. How would I go about using the WakefulIntentService for this? And would I be able to use it in this scenario.

Thanks.


Solution

  • I used AlarmManager, I looked at WakefulIntentService and that gave me an idea on what to do. Thanks again for the help everyone.