Re: [android-developers] Re: Out Of Memory Error with Images loaded through XML

2011-09-15 Thread Ralph Bergmann | the4thFloor.eu
Am 15.09.11 06:47, schrieb Sorab Pithawala:
 I have made a ZIP file containing the code, XML and a small readme.

Why do you do it that way:

h1 = BitmapFactory.decodeResource(res, R.drawable.help1_l);
ImageView im = (ImageView) findViewById(R.id.helpImage);
im.setImageBitmap(h1);

and not like this:

im.setImageDrawable(getResources().getDrawable(R.drawable.help1_l))


take also a look at:

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ImageSwitcher1.html

Ralph

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Out Of Memory Error with Images loaded through XML

2011-09-15 Thread Sorab Pithawala
Hi there,
@Ralph - I do it my way because it seems to me that multiple calls to
getResources() is generally considered to be a bad thing (read it online),
and like Michael said I want to make sure my next Image loads without fail.
That and the fact that in an actual app, you would indeed have quite a few
calls to getResources(). In fact, previously my code used to be that exact
same line, which is why the app crashed when loading the fourth or fifth
image. Supposedly, the GC does not clear the bitmap that is not on screen
fast enough (not sure if it does it at all).

@Michael - Yes, this is exactly the reason why I have done it this way.

Please correct me if I am wrong about the multiple calls to getResources(),
as I have just recently started Android dev.

I also cache the context by using Context context=getApplicationContext();
as that too is used in my app. Does this leak the context in anyway? I know
its off topic but just want to be clear.

Regards,
Sorab



On 16 September 2011 01:59, Michael A. michael.aki...@gmail.com wrote:

 Presumably because he needs to recycle the switched out bitmap
 immediately, rather than wait for Android to decide that it has time
 to clean out the old bitmaps.

 I've run into this issue a lot myself when working with largish
 bitmaps. The GC for bitmaps is pretty rubbish - especially if your app
 has to run on older phones.

 Regards,

 Michael A.

 On Sep 15, 11:53 am, Ralph Bergmann | the4thFloor.eu
 ra...@the4thfloor.eu wrote:
  Am 15.09.11 06:47, schrieb Sorab Pithawala:
 
   I have made a ZIP file containing the code, XML and a small readme.
 
  Why do you do it that way:
 
  h1 = BitmapFactory.decodeResource(res, R.drawable.help1_l);
  ImageView im = (ImageView) findViewById(R.id.helpImage);
  im.setImageBitmap(h1);
 
  and not like this:
 
  im.setImageDrawable(getResources().getDrawable(R.drawable.help1_l))
 
  take also a look at:
 
  http://developer.android.com/resources/samples/ApiDemos/src/com/examp...
 
  Ralph

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: Out Of Memory Error with Images loaded through XML

2011-09-14 Thread Sorab Pithawala
Hi there,
I have made a ZIP file containing the code, XML and a small readme. Download
from BitmapTest.zip http://db.tt/hXH0d00.

Regards,
Sorab



On 14 September 2011 18:56, A. andreabl...@gmail.com wrote:

 Hi Sorab,

 I have a similar issue: please could you provide
 more code to better undestand the solution that you found?

 Thanks,
 A.

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en