title: Wi-Fi connection lost during sleep
body: <p>On an Android 4.1 device, I have "Keep Wi-Fi on during sleep" activated in Android's settings but when my device goes to sleep and I don't wake it up for many hours, the connection to the Wi-Fi is lost. Is this a bug?</p>
  
  <p>Originally in my code I used to have the following:</p>
  
  <pre><code>WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
  this.wifiLock = wifiManager.createWifiLock("mywifilock");
  this.wifiLock.acquire();
  </code></pre>
  
  <p>but I removed this code because Android 4.1 has the feature for keeping the Wi-Fi enabled. Is there something I need to do in my app to keep the Wi-Fi connection enabled?</p>
  
  <p>My code runs as a service with no activity, and I run the service periodically with an AlarmManager. I placed the above code in the onCreate to get executed when the service was restarted each time. Maybe I don't understand what the purpose of the "Keep Wi-Fi on during sleep" is used for. Why would I need a wakelock?</p>
  
  <p>What is also weird is that the connection is not lost on an Android 2.3 device from the same manufacturer. Perhaps this is an Android 4.1 bug?</p>