Blog

I noted that every now and then, Weathrman would get killed due to not being responsive enough to a change of wallpaper offsets (finger scroll, etc.), and decided to take a walk and look at the performance of what we were doing.

I hit three different kinds of issues:

Unnecessary updates. If the offsets applied were the same as those currently set, I was forcing a redraw when there was nothing to draw.

Backing store size. Evidently, the ‘optimal’ canvas depth is 565; up until now, I’ve been keeping ARGB_8888 canvases around. Shifting down to RGB_565 results in a massive improvement of the performance loop.

Image load. The flickr image was being loaded in ARGB_8888, even though we were never going to make use of the transparency data in the backing store. As the rest of the visual change has moved to 565, I do so here, as well.

The net effect is to massively reduce the amount of time we spend rendering, and the size in memory of the backing store. In addition, we’re less peaky when we load a fresh image from Flickr.

All of this should result in fewer cases where Android decides to eject the live wallpaper due to ANR.

While I was at it, I added a few more tweaks; we now track how long we’ve been asleep for, and on becoming visible, reschedule our background timer. You should find that the app is much more likely to keep itself current, now, and should begin updating itself within moments of the phone ‘waking up’.