No Drain, No Pain: Tips for Saving Battery Life Through Applications

Tips and Tricks

TITLE_IMAGE

The topic of battery management on BlackBerry® smartphones seems to come up time and time again. I decided to take some time and write this blog post on the topic to share some of the tips, tricks and best practices which will make your BlackBerry application a good citizen on the BlackBerry smartphone. Hopefully, you’ll learn some simple techniques to improve battery life and to get some vital stats about the cost of certain actions in an application.

Generally, there are three main states that your BlackBerry application will go through in the device:

  1. App is in the foreground, backlight is on, and device is unlocked (i.e. user is in theory interacting with the app)
  2. App is in the foreground, and either the backlight is off or the device is locked (i.e. user was using the app but has since let the device go dormant)
  3. App is running in the background (backlight and device lock state don’t matter)

We will not worry too much about the first state, since your application can use as much as battery power it needs, but we will focus on the second and third states, looking at possible ways to prevent the battery from draining too quickly. Here are some of the tips that you can use to make your application be a good citizen on the device.

Tip #1: If your application is running in the background, then only run what needs to be run. For example, when your application is in the background, threads such as UI, animation and media should be paused. Your application should treat itself as being in the background when the backlight is out or the lock screen is up. One way of identifying whether device is locked or not, is to use the net.rim.device.api.system.ApplicationManager. IsSystemLocked () method. You can also use the net.rim.device.api.ui.UiApplication.getUiApplication ().isForeground () method to determine if the application is in the foreground or not.

Finally, you can use net.rim.device.api.system.Display.getProperties () & Display.DISPLAY_PROPERTY_REQUIRES_BACKLIGHT to see whether the backlight is on or not.

Tip #2: Use the Profiler in the BlackBerry Java IDE to confirm that you contribute as close to 0% extra CPU usage when in the background. Every few % CPU used equals about 5 mA above device idle. Read more information about the Profiler and its usage.

Tip #3: Watch the repaint () operations, regardless of whether application is in the background or foreground, repaint the screen only if and when needed. Especially, if you are rendering OpenGL, it is very battery intensive.

Tip #4: Retrieving an autonomous GPS (aGPS) fix is one of the most expensive battery operations on the device. Alternatively, you can use BlackBerry Criteria to specify the type of fix you need and also you can choose the level of accuracy you need. The details on this subject can be found here.

Tip #5: If you detect low battery, consider notifying the user or stopping battery intensive functions such as LBS, excessive logging, active cellular radio and garbage collection.

For logging, you can the log level to minimum in the Event Logger. This can be achieved using net.rim.device.api.system.EventLogger. getMinimumLevel ().

For cellular radio, you can use push instead of poll. Pushing is vastly more efficient than polling. Whenever you see your application polling regularly for data you should seriously consider implementing the BlackBerry Push service.

For garbage collection, you can use the BB JDE’s Memory Stats or Objects tools to monitor your garbage.

I hope you found these tips useful. If you have your own, I’d like to see them – please share in the comments section below.

About Naveen

Naveenan is an Application Development Consultant with the HTML 5/BlackBerry WebWorks team in Developer Relations at BlackBerry. As a member of the Developer Relations Team, Naveenan manages the technical relationship with enterprise partners. Naveenan's development background consists of a degree in Computer Science and work experience in mobile gaming industry.

Join the conversation

Show comments Hide comments
+ -
blog comments powered by Disqus