android - Initialization of ImageLoaders on App Launch -


how can initialize image loader on app launch can use everywhere in application.i trying use volley library.

 if (mimageloader == null) {         mimageloader = new imageloader(this.mrequestqueue,                 new lrubitmapcache());     } 

i create singleton. here's example project posted:

public class volleysingleton {      private static context mcontext;     private requestqueue mrequestqueue;     private imageloader mimageloader;      private static volleysingleton ourinstance;     public static volleysingleton getinstance(context context) {         if (ourinstance == null) {             ourinstance = new volleysingleton(context);         }         return ourinstance;     }      private volleysingleton(context context) {         mcontext=context;         mrequestqueue = volley.newrequestqueue(context.getapplicationcontext());         mimageloader = new imageloader(mrequestqueue,                 new imageloader.imagecache() {                     private final lrucache<string, bitmap>                             cache = new lrucache<string, bitmap>(20);                     @override                     public bitmap getbitmap(string url) {                         return cache.get(url);                     }                     @override                     public void putbitmap(string url, bitmap bitmap) {                         cache.put(url, bitmap);                     }                 });     }      public <t> void addtorequestqueue(request<t> req) {         mrequestqueue.add(req);     }          public imageloader getimageloader() {         return mimageloader;     } } 

then can image loader statement:

volleysingleton.getinstance(this).getimageloader(); 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -