android - networkimageview to display image in offline mode? after kill the application and reopened. Like the facebook app does -


i referred android developers site , created volley networkimageview singleton class. not maintaining cache image after force close of app , again open app in offline. how make network image view image cache in offline mode. im using lrucache.

note: i'm using networkimageview throughout app. , read somewhere disk cache stored when image url consists cache header. want know , if no header in url how force volley store disk cache of image ?

my code:

public class volleysingletonpattern {  private static volleysingletonpattern minstance; private requestqueue mrequestqueue; private imageloader mimageloader; private static context mctx;  private volleysingletonpattern(context context) {     mctx = context;     mrequestqueue = getrequestqueue();      mimageloader = new imageloader(mrequestqueue, new lrubitmapcache(             lrubitmapcache.getcachesize(mctx))); }  public static synchronized volleysingletonpattern getinstance(context context) {     if (minstance == null) {         minstance = new volleysingletonpattern(context);     }     return minstance; }  public requestqueue getrequestqueue() {     if (mrequestqueue == null) {         // getapplicationcontext() key, keeps leaking         // activity or broadcastreceiver if passes 1 in.         mrequestqueue = volley.newrequestqueue(mctx.getapplicationcontext());     }     return mrequestqueue; }  public <t> void addtorequestqueue(request<t> req) {     getrequestqueue().add(req); }  public imageloader getimageloader() {     return mimageloader; }} 

my lrucache :

public class lrubitmapcache extends lrucache<string, bitmap>     implements imagecache {  public lrubitmapcache(int maxsize) {     super(maxsize); }  public lrubitmapcache(context ctx) {     this(getcachesize(ctx)); }  @override protected int sizeof(string key, bitmap value) {     return value.getrowbytes() * value.getheight(); }  @override public bitmap getbitmap(string url) {     return get(url); }  @override public void putbitmap(string url, bitmap bitmap) {     put(url, bitmap); }  // returns cache size equal approximately 3 screens worth of images. public static int getcachesize(context ctx) {     final displaymetrics displaymetrics = ctx.getresources().             getdisplaymetrics();     final int screenwidth = displaymetrics.widthpixels;     final int screenheight = displaymetrics.heightpixels;     // 4 bytes per pixel     final int screenbytes = screenwidth * screenheight * 4;      return screenbytes * 3; }} 

i have used this , , working me. need add these permission.

<uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.write_external_storage" /> 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -