Open Image Dialog/gridview Is Very Slow
What I have I have an 'open image dialog' in an activity. This 'dialog' only shows folders and compatible images. For this I have a layer with a gridview that I fill with rows that
Solution 1:
In somewhere, the code calls this (data is the full pathname of the image):
DiskLruCache.Editoreditor= mHttpDiskCache.edit(key);
if (editor != null) {
if (downloadUrlToStream(data,editor.newOutputStream(DISK_CACHE_INDEX))) {
editor.commit();
} else {
editor.abort();
}
}
because I don't know how to change it, I modified the url receptor so now instead of reading from the net it reads from a file:
publicbooleandownloadUrlToStream(String urlString, OutputStream outputStream) {
disableConnectionReuseIfNecessary();
HttpURLConnectionurlConnection=null;
BufferedOutputStreamout=null;
BufferedInputStreamin=null;
try {
in = newBufferedInputStream(newFileInputStream(newFile(urlString)), IO_BUFFER_SIZE);
out = newBufferedOutputStream(outputStream, IO_BUFFER_SIZE);
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
returntrue;
} catch (final IOException e) {
Log.e(TAG, "Error in downloadBitmap - " + e);
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (final IOException e) {}
}
returnfalse;
}
But the gridview load the images very slowly. I think it's because the last method. How can I do it better?
Solution 2:
Finally I did all that the Android page said without doing anything for the cache. Now the list loads fast. Maybe I could add a memory cache as Wenhui pointed but it is so fast that it doesn't matter for my purposes.
The test has been done on a SII with a folder containing around 400 with 8Mpx
Post a Comment for "Open Image Dialog/gridview Is Very Slow"