So, here is a known method to share data between activities and avoid frequent loading and releasing resources. However, I read an article (which was referred to on Android official website) that says using a static field might result in memory leak. I am not entirely sure whether these two concepts are the same or not. Would anyone be able to shed some light on it? Any help is appreciated.
Code for my static data holder:
public class Art {
public static Bitmap enemy;
public static Bitmap player;
public static void load () {
enemy = loadBitmap('enemy.png');
player = loadBitmap('player.png');
}
private static Bitmap loadBitmap(String filename) {
//create and return bitmap here
}
}
Code for context memory leak:
private static Drawable sBackground;
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
TextView label = new TextView(this);
label.setText("Leaks are bad");
if (sBackground == null) {
sBackground = getDrawable(R.drawable.large_bitmap);
}
label.setBackgroundDrawable(sBackground);
setContentView(label);
}