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 7783585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:53:00+00:00 2026-06-01T19:53:00+00:00

Does Android maintain a memory cache of application drawable resources and reuse them, or

  • 0

Does Android maintain a memory cache of application drawable resources and reuse them, or it is a good practice to preload all drawables that may be assigned dynamically to different widgets?

For instance:

public static final int[] SETS = {
        R.drawable.set0, R.drawable.set1, R.drawable.set2,
        R.drawable.set3, R.drawable.set4, R.drawable.set5, R.drawable.set6,
        R.drawable.set7, R.drawable.set8, R.drawable.set9, R.drawable.set10};
public Drawable[] sets;

void init() {
    load(sets, SETS);
}

public void load(Drawable[] d, int[] ids) {
    for (int i = 0; i < ids.length; i++) {
        if (ids[i] == 0)
            d[i] = null;
        else
            d[i] = context.getResources().getDrawable(ids[i]);
    }
}
  • 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-01T19:53:01+00:00Added an answer on June 1, 2026 at 7:53 pm

    This smells like an unnecessary pre-optimization. However, android does cache drawables so you don’t have to pre-load them. Relevant code from ApplicationContext

      /*package*/ Drawable loadDrawable(TypedValue value, int id)
                throws NotFoundException {
            .
            .
            .
    
            final long key = (((long) value.assetCookie) << 32) | value.data;
            Drawable dr = getCachedDrawable(key);
    
            if (dr != null) {
                return dr;
            }
    
            .
            .
            .
    
            if (dr != null) {
                dr.setChangingConfigurations(value.changingConfigurations);
                cs = dr.getConstantState();
                if (cs != null) {
                    if (mPreloading) {
                        sPreloadedDrawables.put(key, cs);
                    } else {
                        synchronized (mTmpValue) {
                            //Log.i(TAG, "Saving cached drawable @ #" +
                            //        Integer.toHexString(key.intValue())
                            //        + " in " + this + ": " + cs);
                            mDrawableCache.put(key, new WeakReference<Drawable.ConstantState>(cs));
                        }
                    }
                }
            }
    
            return dr;
        }
    
        private Drawable getCachedDrawable(long key) {
            synchronized (mTmpValue) {
                WeakReference<Drawable.ConstantState> wr = mDrawableCache.get(key);
                if (wr != null) {   // we have the key
                    Drawable.ConstantState entry = wr.get();
                    if (entry != null) {
                        //Log.i(TAG, "Returning cached drawable @ #" +
                        //        Integer.toHexString(((Integer)key).intValue())
                        //        + " in " + this + ": " + entry);
                        return entry.newDrawable(this);
                    }
                    else {  // our entry has been purged
                        mDrawableCache.delete(key);
                    }
                }
            }
            return null;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know does Android caches an application preference? I have an
Can you please does android clear/remove all user preference during upgrade? upgrade my apk
Does upgrading Android application delete files from private data directory? I have tested this
Where does Android emulator keep all its data and itself? Inside the SDK folder
does Android have a best practices guideline on creating & populating the db/tables programmatically
Does android expose an API or somesuch for the development of thirdparty keyboard applications?
Does Android broadcast an intent when the network state has changend, i.e. from GSM
What font file types does Android support (for use with Typeface.createFromAsset, for instance)? I
I need to perform action, when my activity is fully loaded? Does Android have
Does the android compatibility package return to default fragment usage if running 3.0+ or

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.