Marshmallow introduced a new way for devices to preserve battery life by going idle. As an app developer, this means that there is now a difference between your app falling out of the foreground and the device itself being idle.
Before you start to panic about how to wake the device from Doze mode (https://goo.gl/eiAJbo), I recommend taking a moment to figure out if you even need to bust through that idleness.
Doze mode is different in that the entire device is taking a nap, not just the least-recently used apps (such is the case with App Standby). Doze mode is activated when the device is not plugged in, when the screen is locked, and when no motion has been detected for some time. These assumptions imply that the user has put down the device and walked away. So, when they come back and pick their phone up off the counter, it should not have dropped to 30% battery. It should, essentially, be in the exact state it was in when they placed it on the counter. Right?
So, the exceptions to Doze mode should be truly exceptional. There are two situations that I believe would qualify. First, if you have new information that is worth causing the user to walk over and look at their phone. Doze mode honors high-priority messages through Google Cloud Messaging (https://goo.gl/v8l1RH), so that you can respond to important moments, such as that new picture Mom just sent. Just don’t use it as an excuse to download a huge amount of data: try instead including the information needed to display a notification in the push message itself, and then fetch everything else when the user returns (and Doze mode ends).
And secondly, you may have work to do that is time-sensitive. But even AlarmManager (http://goo.gl/HDqEwd) is not exempt from Doze mode. However, just because the alarm will not fire during Doze mode does not mean it is lost. For example, an alarm set with setExact() will actually not trigger while Dozing, but will fire as soon as Doze mode exits. And for most use cases, this is actually fine, because if the user isn’t even holding their device, you probably don’t need to be syncing right now. But if you do have a task that is worth draining the user’s battery when they aren’t there, you can rely on setExactAndAllowWhileIdle() to wake your app even during Doze mode. Check out our previous pro-tip (https://goo.gl/IENTID) on working with alarms and background work for more details.
Ideally, Doze won’t disrupt your app flow too much. But spend some time thinking carefully about when your app may need special consideration. And after making any necessary changes, you can spend some more time testing your app. We’ve created several super helpful adb commands (https://goo.gl/8PGom5) to make it easy to see how your app recovers when coming out of Doze mode.
So happy Dozing, developers. And continue to #BuildBetterApps
- University of Calicut1996
- Entrepreneur, 2014 - present
- CGI GroupSolutions Architect, Enterprise/Consumer Mobility & Cloud Computing, 2005 - 2014
- BEA Systems (Oracle)
F-Stop Media Gallery – Android Apps on Google Play
Now on sale!Replace your clunky stock gallery with a lightweight, fast (even fun) gallery that works with you to organize all the photos and
Top 40 Best Root Apps for Rooted Android phone 2015 (NEW)
Latest Tricks and Tips
Forest Live Wallpaper – Android Apps on Google Play
Forest Live Wallpaper is a nice, relaxing wallpaper with trees blowing in the wind and a sky that changes from dusk till dawn.Don't forget t
SwiftKey Neural Alpha - Android Apps on Google Play
SWIFTKEY NEURAL ALPHASwiftKey Neural Alpha is the world’s first smartphone keyboard software that uses artificial neural networks to predict
Contacts+ | Contactos/Discador - Aplicaciones de Android en Google Play
Contacts+ es la aplicación líder de discado y directorio de teléfono del mundo, impulsada con mensajes, identificación de discador, SMS / bl
wall:tumblr - Tumblr Photos – Android Apps on Google Play
Discover excellent tumblr pictures with wall:tumblr. We compile and high-resolution images with excellent hand select for you. If you want t
Polaris Office + PDF – Android Apps on Google Play
Polaris Office is a free Office solution which offers easy viewing and editing of Microsoft Office documents. PDF also supported.You can con
Publish-On Twitter & Instagram – Android Apps on Google Play
The only app in the world that lets you post to Twitter & Instagram simultaneously - Publish, already being used by over 1 million users, is
Amazon India Shopping – Android Apps on Google Play
Shop on-the-go from millions of products across categories with the FREE Amazon Shopping App. The Amazon Shopping App for Android, offers a
Polycon - Icon Pack (Beta) – Android Apps on Google Play
POLYCON Beautiful, Flat and Material! Polycon is a new icon pack and it's here to bring your device a fresh new look.FEATURES ⋆ Dashboard bu