Understanding Battery Usage in your Android App

Developing an android app can be a difficult and daunting task. There is so much to think about and a lot of the time battery usage is not very high on the list of things to remember. However, it is one of the most important things you need to consider. If your app is draining your user’s battery leaving them with a dead phone, the chances of them uninstalling and never using it again are VERY high. Take this guy for example:

Battery Historian - Understanding battery usage in your android app - App Reviews


He is clearly not happy with this app. In this blog post, we will take a look at Battery Historian and also provide some tips on how to avoid draining a user’s battery.

What is Battery Historian?

Battery Historian is a tool that displays information about your phone’s battery usage in HTML form. It provides a way to analyse the battery usage by showing you information like:

  • What app is in the foreground
  • What apps requested a wake lock and how long the phone was awake for
  • When the mobile radio was in use
  • When the GPS is active

How do I use Battery Historian?

  1. Download and install Go
  2. Follow the instructions on the Github page to set up the battery historian.
  3. Plug in your device and run adb bugreport > bugreport.txt in terminal. This will take a couple of minutes.
  4. Run battery historian. Open localhost:9999 in a browser and select the bugreport.txt. You will then see the battery historian output.
Battery Historian - Understanding battery usage in your android app
Battery Historian 2.0 Graph

You can see from this graph that it shows the battery level and the time. The graph also highlights information like if the phone was in Doze Mode, the charging status and lots of other information. This graph shows my device going from 100% at 7AM to about 10% at 12PM.

Battery Historian - Understanding battery usage in your android app - App Stats
App Stats Tab

There is also information regarding specific apps if you want to select your app and see how it is performing. Navigate to “App Stats” and then select your app from the drop down. You can see some useful information such as how much time the app was running for, the data usage and a lot more information.

This tool is very useful for figuring out what resources the apps are using and figuring out how much time they spend in the background even if you don’t use them.

Some tips for improving Battery Usage in your Android App

  • Avoid wake locks if possible.
  • Batch up cellular operations so as to avoid waking up the device every few seconds.
  • Schedule unimportant operations until the user has plugged into a charger and on WiFi. Things like analytics and logging don’t need to happen in real time.
  • Don’t download data if you don’t need to. Try adjust the queries required when using mobile data vs WiFi.
  • Use the system’s built-in options for background processing – such as the JobScheduler API or the SyncAdapters to sync content only when needed.
  • Remove unnecessary background processes if they are not needed.
  • Test your app on a really low end device for a day and see how/if it runs the battery down.
  • Be careful with location updates. The more you request, the more battery you will use. See more here.
  • Join the Android Performance Patterns Google Plus community and read the official docs about improving battery life.

What tips do you have for reducing the amount of battery usage in your application?


3 responses to “Understanding Battery Usage in your Android App”

  1. Jabin Zhao avatar
    Jabin Zhao


  2. Using cache supported network frameworks ( retrofit, volley, picasso etc) instead of writing own Http helpers, may be another trick about battery draining. Thanks for this useful post Rebecca.

  3. That is a good tip too!