I have a LayerDrawable consisting of 4 Drawables each representing a PNG. I get layers to change to different Drawables as desired, but only a few times. Then debugging will throw an OutOfMemoryError. It's as if the resource manager is not garbage-collecting once I replace each drawable. What am I mssing?
Resources resources = getResouces(); Drawable layer; Drawable[] layers = new Drawable[4] // Initialize the array of layers, omitted layer.setBounds(...) for readability layer = resources.getDrawable(R.drawable.graphic_1_a); layers[1] = layer; layer = resources.getDrawable(R.drawable.graphic_2_a); layers[2] = layer; layer = resources.getDrawable(R.drawable.graphic_3_a); layers[3] = layer; layer = resources.getDrawable(R.drawable.graphic_4_a); layers[4] = layer; // Apply the array to a LayerDrawable LayerDrawable layerDrawable = new LayerDrawable(layers); // Now changing a layer will work layer = resources.getDrawable(R.drawable.graphic_1_b); layers[1] = layer; // But then, ZygoteInit$MethodAndArgsCaller.run() throws OutOfMemoryError layer = resources.getDrawable(R.drawable.graphic_3_b); layers[3] = layer; --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---