android - How to convert URLs to bitmaps, store them in cache, and display in Listview? -
android - How to convert URLs to bitmaps, store them in cache, and display in Listview? -
i'm not asking code, need guidance on approaching problem. i'm new android , i'm doing little project, parse json google images api url links of images of keyword. point parsed json, made listview + arrayadapter, , displayed each url in listview. have figure out how turn these links images (i think using bitmaps), , display them in listview. don't want load them sd card because utilize disk space each image, rather store them in cache. problem is, i can't utilize third-party libraries caching. i've searched on google , found things "lazyload" , "universal image loader" unfortunately seem third-party, not official. found "lrucache", on android developer website best 1 purposes? can allow me know other options have solve problem?
thank you!
you have url image. workflow:
does image exist on device already? if so, read memory. if not, download on http(s). next, save image somewhere on disk don't have re-download next time. display image on ui.don't create more complicated is. caching mechanism in volley, univeral image loader, etc. going build upon same concept , may unnecssary want/need accomplish. here's code (albeit dated) wrote simple app in clear manner:
if (!doescachefileexist(ctx, filename)) { log.d(tag, "no cache exists. downloading."); url url = new url(uri); httpurlconnection con = (httpurlconnection) url.openconnection(); bitmap b = bitmapfactory.decodestream(con.getinputstream()); b = postprocessbitmap(b); cachebitmap(ctx, b, filename); homecoming b; } else { log.d(tag, "found cached file."); homecoming getcachedbitmap(ctx, filename); }
full code can seen here: https://github.com/zaventh/smartsquare/blob/develop/src/com/steelthorn/android/watch/smartsquare/util.java#l48
android caching android-imageview android-bitmap android-lru-cache
Comments
Post a Comment