When working with android development, simple tasks like turning on the screen of your device during code deployment could easily become tiresome and annoying, if you have to do it every few minutes. One solution is to enable “Stay awake” via the “Developer options” of your device. But that is not very energy friendly!.
The following technique allows you to wake up a device during code deployment, and it works with and without instant run. You would still need to unlock it if you use a lock screen. I use dedicated devices for android development so I don’t use a lock screen on them, which is one less of a problem.
Using ActivityLifecycleCallbacks#onActivityResumed, you can acquire a WakeLock here for for example, effectively waking up the device. I put this callback in an Application class that is only used in debug build. Don’t forget to add android.permission.WAKE_LOCK permission to your debug manifest as well.
Here’s an example:
So now, every time you deploy a new code, your device will automatically wake up. If you use instant run, it will even wake up on the current Activity you are working on!.