Questions tagged [wakelock]

Refers to PowerManager.WakeLock, a class from the Android SDK belonging to package android.os. Its responsibility is requesting CPU resources in the context of power management. If no wake locks are taken, Android will shut down the CPU.

The Android Operating System uses its own power management scheme, built on top of the standard Linux one. Since it's mobile-oriented, one of its main goals is to avoid wasting CPU cycles (i.e. power) if no application is running.

That's why every application must request CPU resources, using wake locks. If no wake lock is taken, Android will shut down the CPU in order to save power.

Resources:

534 questions
7
votes
1 answer

Is it possible to hold multiple Wake Locks?

I'm developing a small utility app that scans 2D barcodes, and then submits each barcode to an IntentService where a longer task is performed. When the activity is shown, it should prevent the device from sleeping, until the barcode is processed in…
Mister Smith
  • 27,417
  • 21
  • 110
  • 193
7
votes
1 answer

If a wakelock is acquired and my app crashes, what should I do?

My application has a background service running at all times when a flag is set to true. If this is the case, even if app is down this background service still needs CPU time. If I acquire wakelock (not for "screen on" purposes but for this…
cesarmax
  • 414
  • 1
  • 5
  • 12
6
votes
3 answers

Android: Keep camera-LED on after screen turns off

since i'm at the beginning with Android coding i hesitated to post my question, but now i'm at the point where i can't resist. I have a service which turns on the camera-LED onCreate: @Override public void onCreate() { // make sure we don't…
stefanjunker
  • 367
  • 4
  • 13
6
votes
0 answers

Error "WakeLock: GCM_HB_ALARM release without a matched acquire" in android studio

my app is crashing and I get this error in my logcat : 04-11 23:50:51.278 2294-26973/? E/WakeLock: GCM_HB_ALARM release without a matched acquire! 04-11 23:50:51.317 2294-4859/? E/ExecutionCriteria: Package unavailable for task:…
new user
  • 61
  • 1
  • 4
6
votes
3 answers

Android - Wake lock not acquiring properly, app needs to keep running in standby

In my app, in the onCreate() method of the main activity I am creating a wake lock so that the CPU will keep running if the phone goes on standb/screen turns off. Also in the onCreate method I have an intent to create a service that uses the…
bobby123
  • 1,006
  • 4
  • 14
  • 24
6
votes
2 answers

How to keep the vibrator on indefinitely from a service or receiver

I need to alert the user of certain events by means of: Vibration Notification The vibration should remain on indefinitely until the user ACKs the notification. The problem is vibration stops when the device goes to sleep. I've read the following…
Mister Smith
  • 27,417
  • 21
  • 110
  • 193
6
votes
2 answers

Wake lock continually throws an exception on Nexus 5

We recently got a Nexus 5 to use as a test device. It's running Android 4.4.2. The problem is that it continually spews the following exception as a warning every 2 to 4 seconds: 01-02 22:33:33.482 751-894/? W/Binder﹕ Caught a RuntimeException…
Bjorninn
  • 4,027
  • 4
  • 27
  • 39
6
votes
1 answer

Wake + Wifi lock no effect

My background service is sending messages to a local server as fast as possible. Each message takes normally about 30ms. But when the phone is in sleep mode it takes around 400ms-1000ms (screen off with the 'correct' Wifi-policy) Within my service…
Ion Aalbers
  • 7,830
  • 3
  • 37
  • 50
6
votes
1 answer

Should I call WakeLock before creating a notification?

I'm adding notifications to an Android app and only have the emulator to test with at the moment. When a notification is received, my onMessage() method in my GCMBaseIntentService subclass (GCMIntentService) is called. From here I create a…
6
votes
2 answers

do I need a wake lock in my broadcastreceiver if I'm not starting a service or an activity?

I have a broadcastreceiver called by an Alarm (scheduled with AlarmManager). In this receiver I'm only querying a register from the database, and launching a notification. I readed that a wake lock is needed when a service or an activity is started…
Sergio Viudes
  • 2,714
  • 5
  • 26
  • 44
6
votes
3 answers

wifiLock and wakeLock not working correctly on Android

I am developing an app that needs to use both wifiLock and wakeLock so the audio streaming when the screen is off does not get disturbed. I have tried my app on Android 2.3 and wakeLock and looks like wifiLock work as expected so there is no…
TJ1
  • 7,578
  • 19
  • 76
  • 119
6
votes
2 answers

onStop called before onStart

I have a activity which is called from a AlarmManager. It is an alarm message. When the Activity is called from the Key Guard, the lifecycle goes from onCreate -> onStart -> onResume -> onPause -> onStop and then goes back to onCreate -> onStart ->…
Xisberto
  • 125
  • 3
  • 12
5
votes
2 answers

Android GPS tracking and WakeLock

I need to do background GPS tracking on an Android phone, and I'm currently planning on having two scenarios: When the phone is connected to a (car) charger, get frequent GPS locations (every minute). When the phone is not connected to a charger,…
Ralf
  • 14,655
  • 9
  • 48
  • 58
5
votes
1 answer

Should I use WakeLock in IntentService?

Suppose I use BroadcastReceiver to receive events(intents) that awake the phone even if it is in deep sleep mode (such as incoming data packet on a socket, or incoming text message). Then I forward received data to an IntentService for processing.…
CITBL
  • 1,587
  • 3
  • 21
  • 36
5
votes
0 answers

Proximity wake lock not always turning screen back on

I'm trying to create a custom phone app, and one of the features i'm trying to implement is to turn the screen off when the phone is brought close to face to avoid accidental touches. I have read about the proximity sensor in the android…
David Barishev
  • 534
  • 7
  • 30