Hello,

what is the magic with wake locks?

I try to prevent that the phone is going to sleep.

Here my code (snippet):

public class GPSListenerHandler extends Handler implements
GpsStatus.Listener, LocationListener {

   private WakeLock         wakeLock;

   protected boolean        isWakeLocked;


   public GPSListenerHandler(Looper l, Context c) {

      super(l);

      // ...

      final PowerManager mgr = (PowerManager)
c.getSystemService(Context.POWER_SERVICE);
      this.wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"GPSListener");
   }

   @Override
   public void handleMessage(Message msg) {

      if (msg.arg1 == GPSTrackingService.START) {

         this.wakeLock.acquire();
         this.isWakeLocked = true;

         this.tracking = true;
         startLogging();

      } else if (msg.arg1 == GPSTrackingService.STOP) {

         if (this.isWakeLocked) {
            this.wakeLock.release();
         }
         this.tracking = false;
         stopLogging();
      }
   }

   // ...

}

Now my Android 2.3.x devices going to sleep after round about 10
minutes, my 4.x devices stay awake.


What's wrong?


Ralph

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to