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]);
}
}
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