Multiple instance of RemoteImageLoader are passed to RemoteImageView.setSharedImageLoader
Here is how to reproduce the issue.
- Install remote-image-gallery-sample on a device using android-7/ 2.1. I have just try this on the emulator. I could not reproduce it on newer versions but the problem is still there.
- Start rotating the emulator back and forth.
- You will get a OutOfMemoryError
The cause of the the problem is that we are initializing a static variable -- that depends of the context -- every time the activity is created.
The way I bypass this problem is by having my own static variable on my activity and just creating it once, but this is ugly, unintuitive and is not documented.
What I propose is to create a helper function on RemoteImageView that let you know if the sharedImageLoader has been initialized. And log a warning message if setSharedImageLoader is called twice.
I'm not sure I understand. A static (i.e. class level) field is only created once, when the class is loaded. Re-creating the Activity does not result in a class being unloaded and loaded again. Are you sure this is the cause for the problem you're seeing?
If this is a 2.1 only bug, I would feel inclined to ignore it. 2.1 is deprecated and has largely been replaced by FroYo or Gingerbread. If it is present on other platform versions, too, then this is of course a more serious matter (although I haven't see this happening in our app yet).