Search code examples
androidwakelockandroid-wake-lock

Is wake lock commutative?


Let's say an Android application acquires a wake-lock, and then launches another application by sending it an explicit intent. Does the effect of acquisition of wake-lock last while the other application is in the foreground ?


Solution

  • As described in Keeping the Device Awake it's perfectly natural for a background application to grab and hold a CPU wakelock:

    One legitimate case for using a wake lock might be a background service that needs to grab a wake lock to keep the CPU running to do work while the screen is off. Again, though, this practice should be minimized because of its impact on battery life.

    This action is pretty common. For example, imagine a music playing application. Even though the screen is off, or some other activity is in the foreground, it's fine for a background application to hold a wake lock to keep playing music.

    Although that last line should really take a warning. As described in Wakelocks and Battery Drain those things tend to burn through battery pretty fast; and worse yet, is that it's a pretty common problem to not release them properly, and end up putting the device into a sleepless mode, where it never goes to sleep.