Activating Doze Mode on Android: A Step-by-Step Guide
As mobile devices continue to play a larger role in our daily lives, battery life has become a critical concern for both users and developers. To address this, Android introduced a feature called Doze mode, which helps extend battery life by reducing power consumption when a device is not in use. However, for developers, it’s important to make sure that their apps continue to function properly when the device is in Doze mode. This is why testing an app in Doze mode is crucial to ensuring a positive user experience. Doze mode is particularly useful for users who have to go long periods without access to a power source. However, activating Doze mode can be a bit tricky, especially for those who are not familiar with the process. In this blog, I will provide a step-by-step guide on how to activate Doze mode on Android devices. I will also cover the different methods available for enabling Doze mode, including using the Android Debug Bridge (ADB) command line tool and the Android Emulator. By the end of this blog, you will have a clear understanding of how to activate Doze mode on your Android device and how to test your app in this power-saving state.
Developer Options
To test an Android app in Doze mode, you can use the following steps:
- Connect your device to your development machine and run the app on the device.
- Go to the developer options on the device and enable “Force activities to be resizable.”
- Open the app and set it up so that it is running in the background.
- Put the device in Doze mode by going to the developer options and selecting “Force Doze.”
- Observe how your app behaves in the background while in Doze mode.
Android Debug Bridge (ADB)
Alternatively, you can use the Android Debug Bridge (ADB) command line tool to simulate the conditions of the Doze mode on a device. You can use the following command to simulate the Doze mode:
adb shell dumpsys deviceidle enable
This command will enable the Doze mode on the device. To return the device to its normal state, use the following command:
adb shell dumpsys deviceidle disable
You can also use the Android Emulator to test your app in Doze mode. In the Android Emulator, you can go to the settings and enable the “Battery saver” mode to simulate the Doze mode. Additionally, you can use the following command to simulate the Doze mode in the emulator:
adb shell dumpsys battery unplug
It’s recommended to test your app while in Doze mode, and make sure your app’s critical functions are still working as expected.
Note that, Doze mode can be a bit tricky to test. It’s best to test with a device that is running Marshmallow (Android 6.0) or later version of Android.