Category Archives: Android

Android Drawable Instances – Don’t Share Them!

Android robotRecently I’ve been implementing an animated user interface where the animations are defined in a proprietary file format. When the interface is brought up on Androidâ„¢, the file gets walked and all the View objects created; when an animation takes place, the definitions in the file are converted into Android key frames. Everything seemed to work well… until I imported a file with what seemed like a harmless optimization.

Several buttons in the user interface incorporated a “glowing” effect, basically by having the glow defined in an image file and animating its alpha transparency. The same image file was in use at several locations on the screen, just scaled to match the button. I decided to cache the Android Drawable, creating just one for each image and attaching it to multiple ImageView objects as necessary. As I loaded the file, the repeated copies of the glow image appeared in several places on the screen. Surely this would be more efficient?

Continue reading

Flattr this!