I have a foreground service that runs as long as I have a Wifi connection. During the duration of the service it holds a WifiLock. Everything works fine until I turn off the screen and wait about 15 minutes. My socket that I hold then throws a connection timeout exception because the Wifi disconnects (I see it in the logs and my android.net.wifi.STATE_CHANGE broadcast receiver is started). The Wifi then proceeds and gets a new connection.
Bwt the same thing happens if I remove my WifiLock and instead change the Wifi sleep policy to "never". But without either the wifi is just turned off until the screen is unlocked.
Couldn't find anything that solved this problem, any suggestion/workarounds are appreciated. If not, my service will just use the new connection and I will have to build around this issue.
Using a Galaxy Tab.