FWIW, here is a project where I have implemented a Service that can do
a location check inside of a WakeLock, stopping the service once we
get a fix or a timeout:

https://github.com/commonsguy/cwac-locpoll

On Tue, Jul 24, 2012 at 3:00 AM, Ralph Bergmann | the4thFloor.eu
<ra...@the4thfloor.eu> wrote:
> 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



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.8 Available!

-- 
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