質問

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!

役に立ちましたか?

解決 2

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.

他のヒント

Try running the service as Foreground using notification. This will make sure your service is always alive. When your are done with the job, you can Self Stop the service.

Create a notification, showing that your service is running

 startForeground(NOTIFICATION_ID, notification);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top