2

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.

Alex
  • 2,033
  • 1
  • 24
  • 40

1 Answers1

0

As ahmedre noted this is a bug with Android. I now create a response from the client to make sure the message was received. Otherwise try again momentarily. This is to get around the problem of sending a message when the Wifi just died.

Update

I have not seen this particular issue on newer devices. Originally this behavior occured on the Galaxy Tab.

Alex
  • 2,033
  • 1
  • 24
  • 40
  • How can you use use an AlarmManager to keep wifi alive ? – Mr_and_Mrs_D Nov 13 '13 at 00:59
  • This is a very old question when I was just researching on how to keep socket connection alive indefinitely. See http://stackoverflow.com/questions/15254146/android-persistent-socket-connection-rules for some more details. – Alex Nov 13 '13 at 01:48
  • Thanks a lot for prompt reply ! It is your other question (http://stackoverflow.com/questions/19148765/) that tackles waking the wifi up (the alarm manager is not directly related to wifi - just wakes the phone up during `onReceive()` as you very well know). I was confused cause you sounded to imply that somehow using AM the wifi woke up - except if you meant to use AM to turn sc reen on etc! Have a look here btw for a question of mine on scanning : http://stackoverflow.com/questions/16137268/ – Mr_and_Mrs_D Nov 13 '13 at 02:02
  • Yea, that part was confusing and didn't really add to the answer. But this issue is different from the other question you linked. For this one, the WiFi would just temporarily disconnect while the device was still in coverage. The other one talks about the WiFi disconnecting when the device was out of coverage, but not reconnecting when walking back into coverage unless the screen is turned on. – Alex Nov 13 '13 at 02:44