0

From reading a different thread here in overflow, which is the following: BroadcastReceiver Vs WakefulBroadcastReceiver

The main difference is that the CPU will stay awake in the WakefulBroadcastReceiver and not in BroadcastReceiver. Is there any reason why we want to keep the CPU always awake, or Not?

Community
  • 1
  • 1
Red M
  • 2,609
  • 3
  • 30
  • 50
  • 1
    "Is there any reason why we want to keep the CPU always awake" -- your code does not run when the CPU is asleep. This makes it difficult for you to get your work done. `WakefulBroadcastReceiver` does not cause the CPU to be "always" awake -- it is awake while you complete your work, in your `IntentService`. – CommonsWare Mar 02 '17 at 16:04
  • Right. I meant that it will be awake until the wakeLock is returned then it's won't be awake anymore. But does that mean that we won't be able to get the work done if we are using BroadcastReceiver instead of WakefulBroadcastReceiver? – Red M Mar 02 '17 at 17:55
  • 1
    Perhaps other things are already keeping the device awake (e.g., you happen to be in the foreground). Perhaps your work is very short (<1ms) and so you can do it straight in `onReceive()` of the `BroadcastReceiver`. Perhaps you are doing something else with your own `WakeLock` and do not need `WakefulBroadcastReceiver`, such as using my `WakefulIntentService`. There are many possible patterns here. – CommonsWare Mar 02 '17 at 18:37

0 Answers0