Search code examples
androidandroid-servicewakelockandroid-wake-lock

Android Background Service with PARTIAL_WAKE_LOCK


So...

I have a service that spawns a thread that is listening to data from a device via the device's wifi network. All works well, except that the service seems to pause when the the device is put to sleep.

I've tried PARTIAL_WAKE_LOCK and WIFI_LOCK with no success. I've checked and it says the wake lock is held, but as soon as the device goes to sleep the service stops logging the data. Any thoughts or examples would be greatly appreciated!

Thanks!


Solution

  • So I figured it out. I was improperly calling the WIFI_LOCK. The service was indeed still running, but the wifi connection was going to sleep (I guess). After backing up and starting again, I realized that the WIFI_LOCK was not getting created appropriately. Thanks to Libin for sharing the startForeground answer as well.