1

I am currently developing an app that runs a service from time to time. Currently, the service acquires a wakelock, reads some sensors and sends some information over WIFI (if any). Now what I want to know is weather a wakelock influences sensors and connectivity or not. Is it possible to do these tasks without any wakelock?

Cheers

Schore
  • 133
  • 1
  • 8

1 Answers1

1

A wake lock is essentially used to lock the device in an "awake" state, in which the CPU will be on, and the screen may or may not be on.

It is not possible to do these tasks without a wakelock if the phone is in sleep otherwise, as then the CPU is also in sleep mode. However, if the user is using the device for something else, and your app is in the background, you can do these tasks without a wakelock.

Keep in mind that almost everything you're doing is battery intensive (sensors, WiFi, wakelock) and you should not do it too often so that you don't degrade the user's battery life.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • What does 'CPU is in sleep mode' mean? I can't execute a single line of code or the CPU is running on a low clock? What does a service if it does not acquire a wake lock? Terminate? Freeze? – Schore Dec 16 '12 at 16:05
  • The CPU clock speed is reduced to the minimum required to receive SMS and phone calls and notifications. You will not be able to run your code anymore. AFAIK, a service will pause. – Raghav Sood Dec 16 '12 at 16:08
  • See [this](http://stackoverflow.com/a/5120225/1069068) answer by CommonsWare for more details. – Raghav Sood Dec 16 '12 at 16:10
  • Services don't just get paused when the screen is off, otherwise there's no purpose of Service. They are meant to run all the time in background. However, the components like WiFi or any other may not be available when the device is in sleep mode. – waqaslam Dec 16 '12 at 16:17
  • @Waqas The commonsware answer says that services also get paused. I'm following that – Raghav Sood Dec 16 '12 at 16:19
  • I dont really agree that because I've written Services without WakeLock in which the app connects to a server continuously at fixed intervals and download the data even when the screen is off. You should give a try and experiment it yourself. – waqaslam Dec 16 '12 at 16:27
  • 1
    @Waqas Perhaps you were able to do it in the time between the screen off and lock event, which can be a while I believe. In anycase, I will try it out soon and figure it out for sure :P – Raghav Sood Dec 16 '12 at 16:29
  • leaving the phone all night long with screen-off shouldn't be regarded as "a while" :) Anyhow try it yourself and share your experience – waqaslam Dec 16 '12 at 16:42
  • @Waqas I'll post the results by tomorrow :) – Raghav Sood Dec 16 '12 at 16:43
  • @RaghavSood Isn't there any official information on this topic? I find information about wakelocks really sparse. – Schore Dec 16 '12 at 16:43
  • @user1467594 not that I'm aware of. There should be, but I can't seem to find it. I'll post back my own tests by tomorrow – Raghav Sood Dec 16 '12 at 16:47