When using LocationManager.requestLocationUpdates, do I need a WakeLock?

527 views
Skip to first unread message

iamnoah

unread,
Oct 8, 2010, 9:54:06 AM10/8/10
to Android Developers
Hi,

I'm trying to get a definitive answer to this question:
http://stackoverflow.com/questions/3814852/android-when-using-locationmanager-requestlocationupdates-do-i-need-a-wakelock

Assuming that I receive an RTC_WAKEUP alarm in a broadcast receiver
and hold a wake lock until I have called requestLocationUpdates, is
there any need to retain the wake lock to continue to receive updates
in a timely fashion?

My guess is that there is not, as having to retain a wakelock would
cause all kinds of problems for long running location checks, but an
authoritative word from a platform developer would be good to have as
the documentation is completely silent on this topic.

Thanks!

Mark Murphy

unread,
Oct 10, 2010, 5:50:35 PM10/10/10
to android-d...@googlegroups.com

I strongly suspect that you need to hold a WakeLock for as long as you
are seeking fixes. I am not aware that any location provider has the
ability to wake up the device.

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

_Android Programming Tutorials_ Version 3.0.1 Available!

ste1024

unread,
May 11, 2012, 7:57:35 AM5/11/12
to android-d...@googlegroups.com

Am Sonntag, 10. Oktober 2010 23:50:35 UTC+2 schrieb Mark Murphy:

I strongly suspect that you need to hold a WakeLock for as long as you
are seeking fixes. I am not aware that any location provider has the
ability to wake up the device.

Sorry for digging up this ancient topic, but an trying to find an answer to the same question.
In my app so I am able to receive location updates even if I put the device to sleep, without explicitly holding a WakeLock.
I came across what appears to be the Android 2.2 source of the GpsLocationProvider, and assuming I did not misinterpret the code, it looks like it is really able to wake up the device via the AlarmManager.

Can anyone confirm this?

William Kelley

unread,
May 11, 2012, 8:19:34 PM5/11/12
to android-d...@googlegroups.com


On Friday, May 11, 2012 4:57:35 AM UTC-7, ste1024 wrote:
 
Sorry for digging up this ancient topic, but an trying to find an answer to the same question.
In my app so I am able to receive location updates even if I put the device to sleep, without explicitly holding a WakeLock.
I came across what appears to be the Android 2.2 source of the GpsLocationProvider, and assuming I did not misinterpret the code, it looks like it is really able to wake up the device via the AlarmManager.

Can anyone confirm this?

I am experiencing the same thing. My GPS app runs for hours and hours getting coordinates every 6 seconds, whether it's asleep or not. Either WakeLock is not needed for the LocationManager to work non-stop or one of the other apps I have installed is using WakeLock. I'm assuming the latter, since I have Tasker and AutomateIt running, both off which are time-based services. I guess I should check their permissions for WakeLock. Or they could just be waking the CPU via the AlarmManager?

It makes me wonder if it's necessary for me to add a WakeLock to my app or just rely on the fact that other apps will keep the CPU alive for me.

William Kelley

unread,
May 11, 2012, 8:59:39 PM5/11/12
to android-d...@googlegroups.com
Just a followup: Tasker and AutomateIt both do have "Prevent device from sleeping" (ie WakeLock) as permissions.
Reply all
Reply to author
Forward
0 new messages