Sep 11, 2009
I've been able to lock the screen twice with the current implementation of the app I'm writing (MediaDroid). It's very inconsistently (2 out of about 100 runs) and I'm not sure how to trigger it, so I'm assuming it's some sort of race condition or the number of threads I'm spawning.
View 5 Replies
The activity I'm working on loads a gallery of thumbnails from the sdcard. I believe I'm using most of the best practices described by Romain Guy from his Google I/O talk "Make your Android UI Fast and Efficient". I've implemented an image cache with SoftReferences wrapping my Bitmaps and created an Efficient Adapter for the gallery using the ViewHolder pattern.
What I am doing, which I question, is loading each image via a thread as it is retrieved from the ImageCache...I pass back a default image if the bitmap is null, then update the default image in the ImageViews with the Bitmap is loaded from the sdcard; I'm doing this by posting to a Handler in the Adapter from the thread that loads the image.
So as you can imagine a number of threads are created, about 25 at a time, as the user swipes through the image gallery. Once the user reaches the end of the gallery, the images are only reloaded if the garbage collector has collected them due to the SoftReference. I've been impressed by how well this worked....until the bug mysteriously started appearing. What has happened both times is, all the images in the gallery show the default images, then I get an ANR and with the force close or wait option, I hit force close and the ANR dialog shrinks (but doesn't go away) and the background goes black...then everything just freezes...here's the logs where I believe things start to lock up.
If I press on the screen I get nothing on the device, but in the logs I get
And I have to power down the device.
So if the number of threads is the problem I'm thinking of loading all the bitmaps when the app is first initiated, probably using the AsyncTask class. A question I have though about this is that the docs say that you can only call execute() once...what's happens if some of my Bitmaps are garbage collected?? Do I then call individual threads to reload? I've looked through some of the Google apps, Shelves and Photostream, but they don't seem to be using Bitmaps wrapped in SoftReferences.