Search code examples
androidwakelockpower-management

Is there any way to receive a CPU wake event in Android?


I'm trying to reduce power consumption in an Android application which must do some menial data processing periodically, but not so urgently that it needs to trigger wakes itself.

Is there any way to receive an event when another app or process is waking the phone anyway and then perform some data processing? I'm interested in seeing if this reduces the power consumption below the use of scheduled tasks.

I realize that this is an odd question and may end up being more of a laboratory experiment that an important solution to a problem, but it's something I'd like to try if it's possible.


Solution

  • Yes and there is the special WakefulBroadcastReceiver class just for that:

    Helper for the common pattern of implementing a BroadcastReceiver that receives a device wakeup event and then passes the work off to a Service.

    From my personal experience this is a best practice if you don't need your app to wake up on a specific time / time intervals.