My original problem was that I was downloading a 1.3MB jpeg file and setting this as an image. This resulted in out of memory exceptions. Apparently now the server resizes the photo before I download it. However I am still getting the OOM expections. What is the easiest way to measure the size of the file that I download?
EDIT I should also mention that this runs fine on an emulator but is falling over when running on a G1
public Drawable getImage() throws IOException, MalformedURLException {
InputStream is = (InputStream) new java.net.URL(url).getContent();
return Drawable.createFromStream(is, "name");
}
What matters are the dimensions of the image your are downloading/loading. The memory usage will be roughly width*height*2 bytes (or *4 bytes if the image is loaded in 32 bits.) BitmapFactory provides a way to read an image’s dimensions without loading the entire image. You could use this to see how big the image is going to be in memory before loading it.