Tag: github libraries

Understanding Battery Usage in your Android App

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?

Book Dash Android App

Book Dash Android App

I have been working on this app for a couple of months and I am SOOO excited to share it with everyone. The app that I have made is for a NPO called Book Dash. Their cause has inspired me and I decided I wanted to make an app for them that would showcase their amazing work.

What is Book Dash?mobile_screenshot1

Book Dash gathers volunteer creative professionals to create new, African storybooks that anyone can freely translate and distribute.

Why Book Dash?

Children in South Africa need more books but they cost too much when purchased from publishers. The cheapest books have no publisher – then the only cost is printing. So our participants do the work of publishers in a single day. After that, anyone can get print runs sponsored and put finished books into the hands of children.

We believe every child should own a hundred books by the age of five. In South Africa, that means giving 600 million free books to children who could never afford to buy them. Every day we lose, more children grow up unable to read and write well, and to enjoy the worlds that books open up.

The app is a place where you can get access to these books (for free of course), you can download them and read them when you want. The beauty about these books is that they are available in different languages – English, Zulu, Xhosa, Afrikaans and Sepedi. One of my favourite books from the current collection is “Singing the Truth” which is a story about Miriam Makeba.

Onto the app:

When I was building this app, I really wanted to make it a beautiful material app, which obviously cannot be complete without a beautiful icon. I approached Michael Cook from Cookicons and asked him to come up with something cool – obviously he didn’t disappoint. This is what he made:

Book Dash Icon by Michael Cook
Book Dash Icon by Michael Cook

I love the way the “b” and the “d” form a smiling face. Thanks Michael for the awesome work!

The next cool part about the app: it is open source! Part of the book dash policy is to be completely transparent with their work, which means all their stuff is free to download, including the source code of the app.

Pretty cool right?

The app is in open beta at the moment:

Become a tester.

Download the app

Github Repo

Some screenshots from the app:


Let me know what you think!

Monthly Android Morsels [November 2015]

Monthly Android Morsels [November 2015]

Just a small list of things related to Android development that I have found useful this month. Hope you find them useful too!

  • Android Design: A nice new way to edit your theme and see its effect in Android Studio. Click Tools -> Android -> Theme Editor
Android Theme Editor
Android Theme Editor
  • Android XML optimisation: Tired of creating dummy text strings in the strings.xml file? Or want to see things in the Design View but it’s supposed to be hidden in the real view?

You can use the nifty tools namespace to make things visible for design purposes but have no affect in your app. Add the tools namespace to your XML file and you can override things such as visibility and text. Even though android:visibility is set to gone, using tools:visibility to visible, the view will be visible in the Design View but not in the real implementation.Very handy for complex layouts.



Using Design time
Using Design time attributes

What cool Android things have you discovered recently?