Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7835197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:32:42+00:00 2026-06-02T13:32:42+00:00

I have been trying to learn as much as possible about Android development with

  • 0

I have been trying to learn as much as possible about Android development with specific focus on performance since many apps in the Play store today are sluggish. I have found/been directed to many articles/videos.

One specific article about image caching is at: http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html

The author has code available at: http://code.google.com/p/android-imagedownloader/source/browse/trunk/src/com/example/android/imagedownloader/ImageDownloader.java

Which Google seemed to take a version of into and put into their sample classes at: http://developer.android.com/resources/samples/XmlAdapters/src/com/example/android/xmladapters/ImageDownloader.html

In general it is solid, except for what I think is a flaw in the caching. It uses a soft / hard cache that puts / gets things into the hard cache because the Android system resets the soft cache quite often.

Looking at the code though, one starts to wonder if the hard cache would get accidentally reset every time the parent class is instantiated.

First the soft cache:

    // Soft cache for bitmaps kicked out of hard cache
    private final static ConcurrentHashMap<String, SoftReference<Bitmap>> sSoftBitmapCache =
        new ConcurrentHashMap<String, SoftReference<Bitmap>>(HARD_CACHE_CAPACITY / 2);

Now take a look at the hard cache:

    // Hard cache, with a fixed maximum capacity and a life duration
    private final HashMap<String, Bitmap> sHardBitmapCache =
        new LinkedHashMap<String, Bitmap>(HARD_CACHE_CAPACITY / 2, 0.75f, true) {
        @Override
        protected boolean removeEldestEntry(LinkedHashMap.Entry<String, Bitmap> eldest) {
            if (size() > HARD_CACHE_CAPACITY) {
                // Entries push-out of hard reference cache are transferred to soft reference cache
                sSoftBitmapCache.put(eldest.getKey(), new SoftReference<Bitmap>(eldest.getValue()));
                return true;
            } else
                return false;
        }
    };

The hard cache is not static, while the soft cache is static. So the hard cache instance and therefore items get cleared with the life of the instance of the class.

The reason I think this is true is that I noticed my application with a ListView/ImageView, was downloading the image every time and never caching it. It was all done asynchronously, but still hitting the net every time. I verified this by putting a Log.d() statement inside my method that hits the web and seeing when/how often it was called.

Adding the static keyword fixed the issue and my application is much more performant.

I am not sure why this is the case as there is only one instance of the ImageDownloader class in my adapter as shown in the example:

private final ImageDownloader imageDownloader = new ImageDownloader();

THE QUESTION

With all of that said, has anyone else experienced this??? Or am I a combination of crazy/wrong somehow. I am no Java/Android/JVM/Dalvik/WeakReference/SoftReference expert, but something seems a bit off. I don’t know why sHardBitmapCache was not made static, but when I made the change my application stopped hitting the web so much (saving on data costs / battery drainage / performance improvements).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:32:55+00:00Added an answer on June 2, 2026 at 1:32 pm

    You are correct, this is a typo on my part.

    I have fixed the code in the android source tree. Thanks for this feedback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to learn more about lambda expressions lately, and thought of
I am currently trying to learn Android. Have been reading tutorials and manual for
I have been trying to learn a bit more about delegates and lambdas while
I have been trying to learn multi-threaded programming in C# and I am confused
I have been trying to learn how to add testing to existing code --
I have been trying to learn Erlang and have been running into some problems
I have been trying to learn a cross platform language with a fast learning
Hi I have been trying to learn Javascript using codeacademy.com and I have reached
I am trying to learn assembly my self, and I have been reading different
I have been trying to learn Yii without luck. I find Zend Framework, Kohana,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.