How Twitter used Doze in Android 6.0 Marshmallow to Improve Notification Performance

December 21, 2015


Link copied to clipboard

Posted by Laurence Moroney, Developer Advocate

In October, we published a blog post about how Google Cloud Messaging (GCM) works with Doze in Android 6.0 Marshmallow to bring performance and usability improvements to the user. In this scenario, normal priority messages allow the device to stay in Doze, while high priority messages take the device out of Doze. For a great example of this capability and best practices on Android, we’ve spoken with the engineering team at Twitter.

Twitter has researched extensively which messages should get high priority -- given that this priority can awaken a device in Doze. To meet their particular need, Twitter wanted Direct Messages to be delivered on high priority, where mentions would be at normal priority.

Luke Millar, Android Engineering Manager at Twitter commented "With Android M we have a greater ability to be good citizens when it comes to conserving battery life. This feature lets us specify which notifications will wake up a device in Doze and which ones won't. Normally, we tell GCM to wait to deliver push notifications until the next time the user's phone wakes up. However, users expect to receive some push notifications immediately, like notifications for Direct Messages, so we set those as high priority. It's nice being able to specify when and how those notifications make it to our users."

To test Doze, Twitter’s engineers followed the steps outlined on the Android Developers site. These guide you to use adb commands to simulate doze on either a physical or virtual device. Following this method, Twitter was able to successfully test how their messaging priorities would work in a real-world environment.

One other best practice that Twitter used was in transmitting larger payloads, such as when delivering Twitter Highlights. In this case, they opted to pass metadata in the notification, which was then used to sync the application to get the requested Highlights. In other words, they didn’t transmit the contents of Highlights in a notification, instead triggering a sync mechanism to update the contents of the app.

For more details on using GCM with your app in standby environments, check out the documentation.
You can learn more about Google Cloud Messaging and how to use it for notifications in your Android, iOS and Web Applications at the Google Developers site here.