Accessing cached Images from LruCache Implementation












0














I have a GridView with images and i have populated it using Volley and cached the images using the below links. I want to access the selected image of GridView in a new activity from the cached implementation. I have searched here on StackOverflow but could not find how to access the cached images using their key(int this case the URL). i have followed these links but couldn't find anything:



Jake Whartons Volley CUstomization



VolleyImageCacheExample



Do I have to use the same LruCache object created in ImageLoder object in the second activity or is there any other way?



Imageloader object in Singleton class



This is the default implementation of LruCache object used. If someone could explain using the code below?



imageLoader = new ImageLoader(requestQueue, new ImageLoader.ImageCache() {

private final LruCache<String, Bitmap> cache = new LruCache<>(10);

@Override
public Bitmap getBitmap(String url) {
return cache.get(url);
}

@Override
public void putBitmap(String url, Bitmap bitmap) {
cache.put(url, bitmap);
}
});


Assuming that i have a custom class BitmapCache that extends LruCache and implements ImageCache, please guide me how can i access the cache in 2nd activity to access the images cached



public class LruCacheClass extends LruCache<String,Bitmap> implements ImageLoader.ImageCache {

public LruCacheClass(int maxSize) {
super(maxSize);
}



@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);

}}









share|improve this question





























    0














    I have a GridView with images and i have populated it using Volley and cached the images using the below links. I want to access the selected image of GridView in a new activity from the cached implementation. I have searched here on StackOverflow but could not find how to access the cached images using their key(int this case the URL). i have followed these links but couldn't find anything:



    Jake Whartons Volley CUstomization



    VolleyImageCacheExample



    Do I have to use the same LruCache object created in ImageLoder object in the second activity or is there any other way?



    Imageloader object in Singleton class



    This is the default implementation of LruCache object used. If someone could explain using the code below?



    imageLoader = new ImageLoader(requestQueue, new ImageLoader.ImageCache() {

    private final LruCache<String, Bitmap> cache = new LruCache<>(10);

    @Override
    public Bitmap getBitmap(String url) {
    return cache.get(url);
    }

    @Override
    public void putBitmap(String url, Bitmap bitmap) {
    cache.put(url, bitmap);
    }
    });


    Assuming that i have a custom class BitmapCache that extends LruCache and implements ImageCache, please guide me how can i access the cache in 2nd activity to access the images cached



    public class LruCacheClass extends LruCache<String,Bitmap> implements ImageLoader.ImageCache {

    public LruCacheClass(int maxSize) {
    super(maxSize);
    }



    @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);

    }}









    share|improve this question



























      0












      0








      0







      I have a GridView with images and i have populated it using Volley and cached the images using the below links. I want to access the selected image of GridView in a new activity from the cached implementation. I have searched here on StackOverflow but could not find how to access the cached images using their key(int this case the URL). i have followed these links but couldn't find anything:



      Jake Whartons Volley CUstomization



      VolleyImageCacheExample



      Do I have to use the same LruCache object created in ImageLoder object in the second activity or is there any other way?



      Imageloader object in Singleton class



      This is the default implementation of LruCache object used. If someone could explain using the code below?



      imageLoader = new ImageLoader(requestQueue, new ImageLoader.ImageCache() {

      private final LruCache<String, Bitmap> cache = new LruCache<>(10);

      @Override
      public Bitmap getBitmap(String url) {
      return cache.get(url);
      }

      @Override
      public void putBitmap(String url, Bitmap bitmap) {
      cache.put(url, bitmap);
      }
      });


      Assuming that i have a custom class BitmapCache that extends LruCache and implements ImageCache, please guide me how can i access the cache in 2nd activity to access the images cached



      public class LruCacheClass extends LruCache<String,Bitmap> implements ImageLoader.ImageCache {

      public LruCacheClass(int maxSize) {
      super(maxSize);
      }



      @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);

      }}









      share|improve this question















      I have a GridView with images and i have populated it using Volley and cached the images using the below links. I want to access the selected image of GridView in a new activity from the cached implementation. I have searched here on StackOverflow but could not find how to access the cached images using their key(int this case the URL). i have followed these links but couldn't find anything:



      Jake Whartons Volley CUstomization



      VolleyImageCacheExample



      Do I have to use the same LruCache object created in ImageLoder object in the second activity or is there any other way?



      Imageloader object in Singleton class



      This is the default implementation of LruCache object used. If someone could explain using the code below?



      imageLoader = new ImageLoader(requestQueue, new ImageLoader.ImageCache() {

      private final LruCache<String, Bitmap> cache = new LruCache<>(10);

      @Override
      public Bitmap getBitmap(String url) {
      return cache.get(url);
      }

      @Override
      public void putBitmap(String url, Bitmap bitmap) {
      cache.put(url, bitmap);
      }
      });


      Assuming that i have a custom class BitmapCache that extends LruCache and implements ImageCache, please guide me how can i access the cache in 2nd activity to access the images cached



      public class LruCacheClass extends LruCache<String,Bitmap> implements ImageLoader.ImageCache {

      public LruCacheClass(int maxSize) {
      super(maxSize);
      }



      @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);

      }}






      android android-volley android-lru-cache






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 0:22

























      asked Nov 13 '18 at 23:50









      james

      2618




      2618
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I have found the answer
          here



          The reason was that i had resized the ImageView while getting the image from cache. Cache only returns the image that has the size that of the originally saved.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291146%2faccessing-cached-images-from-lrucache-implementation%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I have found the answer
            here



            The reason was that i had resized the ImageView while getting the image from cache. Cache only returns the image that has the size that of the originally saved.






            share|improve this answer


























              0














              I have found the answer
              here



              The reason was that i had resized the ImageView while getting the image from cache. Cache only returns the image that has the size that of the originally saved.






              share|improve this answer
























                0












                0








                0






                I have found the answer
                here



                The reason was that i had resized the ImageView while getting the image from cache. Cache only returns the image that has the size that of the originally saved.






                share|improve this answer












                I have found the answer
                here



                The reason was that i had resized the ImageView while getting the image from cache. Cache only returns the image that has the size that of the originally saved.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 0:51









                james

                2618




                2618






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291146%2faccessing-cached-images-from-lrucache-implementation%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to pass form data using jquery Ajax to insert data in database?

                    National Museum of Racing and Hall of Fame

                    Guess what letter conforming each word