In a nutshell, I have/am trying to create reusable UI components in
XML.  I created a dead simple project that only fires an activity to
show the UI.  It can be downloaded here:

http://dl.dropbox.com/u/409429/Bitmap%20Bg%20Test.zip

I have a "base_form.xml" component that is referenced
(setContentView()) in "BaseForm.java", a base Activity.  The
base_form.xml is a FrameLayout where the background is set to a
drawable (a 16 kb png).

I now have "LoginForm.java" that extends BaseForm and a subsequent
"login_form.xml" component.  This login_form component is inflated in
LoginForm.java and "appended" to the view and remember, the view was
set in BaseForm.java via setContentView(R.layout.base_form).

It should be noted that in the BaseForm.java there is a method called
"cleanupDrawables()" which recycles the bitmap being used in the
FrameLayout and sets various things to null.  It even explicitly calls
System.gc() (I've tried it without and still the same issue).

Upon firing the app, everything works fine.  UI loads up and displays
properly.

Now, hit the back button.

Now, open the app again.  Everything is fine.

Hit the back button again.

Now open the app again.  Breaks with this exception:

FATAL EXCEPTION: main
E/AndroidRuntime(  405): java.lang.RuntimeException: Canvas: trying to
use a recycled bitmap android.graphics.bit...@44f4c150


So after discussing this issue with some other engineers it appears it
is a bug in the garbage collector that is occurring after the 2nd
sweep.  Apparently a very similar bug existed in early .Net.

A solution may be to instead of defining the background in XML to load
a bitmap using BitmapFactory and explicitly set the background of the
FrameLayout in Java.  This is undesirable as it doesn't really allow
me to create reusable UI components in XML.

Any help is greatly appreciated.


Also, it appears this is a bug that is "declined" by the Android
team.  "Use less memory in your app" was the original solution
suggested by Romain Guy.

http://code.google.com/p/android/issues/detail?id=8488

-- 
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

Reply via email to