- Subscribe to RSS Feed
 - Mark as New
 - Mark as Read
 - Bookmark
 - Subscribe
 - Email to a Friend
 - Printer Friendly Page
 - Report Inappropriate Content
 
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
	
				
	




