Peter_vdL

Making the world a Bitmap better

by Peter_vdL Motorola 07-18-2012 09:50 AM - edited 07-25-2012 07:15 AM

It's not every day that a software engineer can go home and say "Today, I made the world a little bit better place," but today is one of those days for me.  

 

A request came in recently for me to help resolve some problems with an app that ran fine on some devices, but failed on others. The kicker was that this was an app to be used by Child Advocates for ChildNet, a Community Based Care (CBC) Lead Agency for the Department of Children & Families (DCF) in Broward County, FL.  DCF is the department that looks after children who have been failed by their parents, or who have no parents. The app problems were delaying deployment. There’s a lot of karma in helping ChildNet. I set up a call with Stewart Lane, Project Manager and Developer of mobile applications, and did a lot of technical  preparation over the weekend around the issue that had been highlighted to me - VPN connectivity.



Figure 1: Department of Children & Families is the agency that looks after children with no parents, or children who have been let down by their parents - it's no basket of flowers.

This morning, when I got on the phone with Stewart, he explained that he had done some testing and eliminated the VPN issue - VPN connectivity was definitely not the problem.  Great!  But also terrible! It meant all my preparation was for nothing.  

We set up a screen share and started work on the problems. The first step in resolving a bug is to reproduce it.  Stewart and I eventually reproduced both problems.  From there it was a matter of going through the adb log with a fine-tooth comb, looking for anomalies.  All bugs yield eventually, if you put enough effort into them.  I was able to identify the root cause of both issues. It turned out to be the same cause in both cases.

When you create a Bitmap from an image file, you typically need 4 bytes of memory for every pixel.  For an 8 MP camera that’s 32 MB of data.  As an image file, that picture can be stored in compressed JPG format in 2 to 5 MB (the amount of compression depends on the distribution of colors in 64x64 pixel squares in the image).  But as a bitmap, every pixel must be represented in memory - that’s what “bitmap” means - it maps pixels to bits in memory or in a framebuffer.  When you create a bitmap from an image file, you place a heavy demand on memory allocation.  The Bitmap class simply wanted more memory than the runtime system could provide, with the result that the app stopped dead.  That also explained why it happened on some devices and not others - different amounts of memory and different processes running led to different results.

I gave Stewart a workaround in XML.  Applications running at API Level 11+ (Honeycomb or later) can have an android:largeHeap="true" on the <application> element in the XML manifest file to request a larger heap.   That allowed testing to proceed immediately.  I've got a bit more work to do, to propose algorithm or data structure changes that reduce the demand for memory.   I’ll probably suggest cutting down the resolution of images by using the inSampleSize option in BitmapFactory.Options.  But the main thing is the agency is no longer blocked on an app issue that only shows up on some devices.

Even better than that, the Child Advocates helping children in the care of the State of Florida, can now do their job using the latest mobile technology.  And that means this software engineer (me) had the rare but heart-warming experience of contributing, in a very small way, to "making the world a better place."  It feels good!  

Peter van der Linden
Android Technology Evangelist

Post a Comment
Be sure to enter a unique name. You can't reuse a name that's already in use.
Be sure to enter a unique email address. You can't reuse an email address that's already in use.
Type the characters you see in the picture above.Type the words you hear.
MOTODEV for Enterprise
Welcome...

Comment on our blog and tell us how we can help you build and distribute enterprise mobile applications on Motorola devices.

Subscribe to our RSS feed Subscribe via RSS

Follow Us

Our Blog & Comment Policy
Opinions expressed here and in any corresponding comments are the personal opinions of the original authors, not of Motorola. The content is provided for informational purposes only and is not meant to be an endorsement or representation by Motorola or any other party.

Remember, when you comment, please stay on topic and avoid spam, profanity, and anything else that violates our user guidelines. All comments require approval by Motorola and can be rejected for any reason.

For customer support issues with your Motorola phone go to the Motorola customer support website.
Blogroll