title: My app drains battery even that I release wake lock
body: <p>I'm building a simple app that has <code>BroadcastReciever</code> that listens to PHONE_STATE:</p>
  
  <pre><code>        &lt;receiver android:name=".PhoneStateBroadcastReceiver" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.PHONE_STATE" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  </code></pre>
  
  <p>In the <code>BroadcastReciever</code>'s <code>onRecieve()</code> I start a service when the state is <code>OFFHOOK</code> and stop the service when the state is <code>IDLE</code>:</p>
  
  <pre><code>public class PhoneStateBroadcastReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
  
          Bundle bundle = intent.getExtras();
  
          String state = bundle.getString(TelephonyManager.EXTRA_STATE);
          if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
              context.startService(new Intent(context, ProximityService.class));
          }
          else if(state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
              context.stopService(new Intent(context, ProximityService.class));
          }
      }
  
  }
  </code></pre>
  
  <p>In the service I'm registering proximity sensor listener, and creating a <code>WakeLock</code> so the screen will turn off well while on call.
  After the call ends I stop the service, and in its <code>onDestroy()</code> I'm unregistering the listener and release the <code>WakeLock</code>.
  But it seems that something is not releasing out there because I see a huge battery drain from my app (30%).</p>
  
  <p>I put a Log when the listener unregistering and also on the <code>WakeLock</code> release, and I can see that the <code>WakeLock</code> is released and the listener is unregistered successfully (I can also see the Log from <code>SensorManager</code> that the listener is unregistered).</p>
  
  <p>What am I missing here?
  That's really annoying.</p>
  
  <p>Some code of the service:</p>
  
  <pre><code>public int onStartCommand(Intent intent, int flags, int startId){
  
      Log.d("CALL", "Service started");
  
      // Get an instance of the sensor service, and use that to get an instance of
      // a particular sensor.
      mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
      mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
  
      mSensorManager.registerListener(this, mProximity, SensorManager.SENSOR_DELAY_NORMAL);
  
      mAudioManager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
  
      mPowerMngr = (PowerManager) getSystemService(Context.POWER_SERVICE);
      try{
          mWakeLock = mPowerMngr.newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, "Proximity");
  
          if (!mWakeLock.isHeld()) {
              Log.d("CALL", "Wake lock acquired");
              mWakeLock.acquire();
          }
      }
      catch (Exception e){
          mWakeLock = null;
      }
  
  
      return START_STICKY;
  }
  
  public void onDestroy(){
      super.onDestroy();
      mSensorManager.unregisterListener(this);
  
      if (mWakeLock != null) {
          if (mWakeLock.isHeld()) {
              Log.d("CALL", "Wake lock released");
              mWakeLock.release();
          }
      }
  
  
              Log.d("CALL", "Service stopped");
      }
  </code></pre>
  
  <p>The log I see:</p>
  
  <pre><code>09-30 03:35:09.120: D/SensorManager(21565): unregisterListener:: disable all sensors for this listener,  listener = com.eladaharon.android.proximity.ProximityService@41a31a18
  09-30 03:35:09.125: D/CALL(21565): Wake lock released
  09-30 03:35:09.125: D/CALL(21565): Service stopped
  </code></pre>
  
  <p>Thanks a lot!
  Elad</p>