The Secret Art of Battery Testing on Android
Make sure your Android app isn't draining users' phone batteries with these battery analyzer tools and tips for reducing power usage.
Join the DZone community and get the full member experience.Join For Free
As much as we love our technology, it has its limits. Just like we only have so much energy to go run a marathon (who am I kidding, I don’t run, I look like Jabba the Hutt), phones burn through a finite amount of energy resources used by apps before we need to fill them back up with juice.
There are a lot of battery testing resources when it comes to Android application testing. There’s even a native battery analyzer that’s built into Android’s OS. Thankfully, there are also several apps in the Google Play store that’ll help narrow down your app’s battery usage. We’ve narrowed it down to some of our favorites. We also cover a sample battery testing cycle and suggest possibilities as to why your app might be using too much power.
Note that none of these require root access, which is, for the intents and purposes of testing, just fine — most of your user base probably haven’t rooted their phones.
Android’s Built-In Battery App
The native battery analyzer can analyze each application and identify the one that’s gulping down the most juice, which is immensely useful right out the gate. All Android builds have a native battery analyzer (accessible by going to Settings > Device > Battery). One of the most practical benefits of the native battery analyzer is its ubiquity; it comes preinstalled on all Android devices. If your test phone library has, say, 20 phones, you won’t have to install it individually on each phone.
When you open this UI, you’ll see the charge amount, a list of your apps with a percentage of battery usage, and a time frame in days, hours, minutes, and seconds. For example: 1d 9h 11m 7s.
This functionality can give you some useful information, but it’s difficult to focus on your app at the precise moment you’re targeting, because to reset the stats, you have to charge fully to 100% and then unplug the device. Doing that in a test cycle can be time consuming, although the stats hold up for accuracy if you have the time.
GSam Battery Monitor
Unlike the native Android battery analyzer, the GSam Battery Monitor can reset testing cycles on the fly, which means you don’t have to drain and recharge the battery to do your application’s power monitoring.
Battery usage settings you can monitor include: App power usage since the phone was last unplugged, app power usage since the phone’s last full charge, and app power usage since the screen was last shut off. The most useful part about these features is that you don’t have to wait to fully charge to get an information reset, and the GSam Battery Monitor can also tell you which functions of your app cause the most battery use.
Another helpful feature is that you can export your app’s analysis and send it via email, making it easy to import the information into project management software. Your product manager will breathe a little easier with all your development data in one place.
Clean Master is another battery testing app with a particularly useful function: Notifications. It’ll let you know if an app is battering (pun intended) the phone’s CPU or battery. Knowing that you’ll be notified with battery or CPU usage problems on the fly will give you more time to focus on other testing issues in the meantime.
While CPU usage issues don’t necessarily have a direct correlation on battery use, the CPU Cooler in Clean Master’s Tools section is handy regardless. This will show if your app is overusing the CPU in any fashion. This tool can help you hunt down problems with overall performance of your app, such as code or design issues.
Examples of Application Functions That Might Tax Battery
Ask yourself these questions if you’re concerned about potential battery abuse:
Does your app handle large amounts of data to/from it? An example: Can users export or import a large file such as photos or video?
Does your application handle streaming?
Does your application do a lot of location checking?
Does your app send analytic data from your app to a 3rd party like Google Analytics?
Does your app frequently sync between the user and a server?
Does your app use excessive wakelocks (when your app keeps the phone awake to send or receive data from your server – or another function)?
We recommend you run Clean Master to monitor battery usage spikes just in case of any anomalies.
How to Perform Battery Testing
Battery testing is something you’ll need to do in a methodical way. While every application is different, we’ve come up with an example of a mobile app testing workflow.
1. Set your phone/app up for the test (get ready to sync, or get ready to download/export/stream, etc).
2. Note your current battery stats (overall percentage, percentage used by your app currently, etc).
3. Perform the test.
4. Note the new battery stats. Keep a log of this data for comparison purposes.
5. Repeat testing for any features/functions that could potentially be problematic.
6. Do this testing with varying levels of overall battery (low/half/full), noting any differences along the way.
7. Confirm that your app’s other features/functions are working properly. For example, if your user turns off location checking in an application that needs geographic information, what happens to battery usage?
When it comes down to testing your app’s battery usage, using different angles of attack is the best approach. Each of these monitoring services we mentioned will help you get a better fix on what you need to improve upon, and with mobile apps, it’s all about efficiency.
Dennis Lee contributed to this post.
Published at DZone with permission of Sam Colt, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.