title: Android Wakelock not working when screen is off
body: <p>I m trying to implement wake lock and wifi lock for  a service. More about my scenario in this like: <a href="https://stackoverflow.com/questions/13359111/wakelock-implementation-in-a-service">Wakelock implementation in a service</a>. I m acquiring during start and releasing when the service gets destroyed. I want to monitor the battery consumption for my project, though I understand that, this approach is not good. But when my phone screen is off, it is not working. I have enabled the option: Keep Wifi on during sleep. As soon as my screen turns off, my service stops.I m using the snippet :</p>
  
  <pre><code>PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
  wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Lock");
  if(!wakeLock.isHeld())
  {
  wakeLock.acquire();
  }
  Log.d(TAG,"Acquired Wake lock successfully");
  wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
  wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF , "WiFi LockTag");
  if(!wifiLock.isHeld())
  {
  wifiLock.acquire();
  }
  Log.d(TAG,"Acquired Wifi lock successfully");  
  </code></pre>
  
  <p>//TO RELEASE</p>
  
  <pre><code>try{
  wifiLock.release(); 
  }catch(Exception e){
  e.printStackTrace();
  Log.d(TAG,"Exception while releasing WakeLock :: Can be ignoredd");
  }
  </code></pre>
  
  <p>Any idea of why this is happening ? Thanks in advance!</p>