[android-developers] Re: How to resolve outOfMemoryError - Bitmap size exceeds VM budget

2011-09-23 Thread joaocruz04
I found a solution, thanks to Streets of Boston and laminina.

Since every app uses 2 images (background and other image), i created
2 images in my Application class (global variables) and not in the XML
(laminina idea). Each app at the onCreate/onResume phase will call
these images from the Application, destroying  its previous instances
and creating the new ones the way Streets of Boston said.

So at most, i have 2 images in memory. Works like a charm :)

Thanks to your replies!

On Sep 23, 6:13 am, ashok chakravarthy ashoki...@gmail.com wrote:
 You can  try the approach suggested by streets of bosten or you can try
 something like below

 i). create baseactivity and all remaing activities extends this activity
 ii). override onKeydown in the base actiivty
 iii).finish the previous activity when you move to next activity. and when
 you press the back on the activity based on the index start the previous
 activity.

 Thanks,
 Ashok.







 On Fri, Sep 23, 2011 at 6:06 AM, lbendlin l...@bendlin.us wrote:
 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

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


[android-developers] Re: How to resolve outOfMemoryError - Bitmap size exceeds VM budget

2011-09-23 Thread Streets Of Boston
Good to know you got it working.

Just checking;
You put images in 2 global vars in your application object. Be sure that 
these images are not (Bitmap)Drawables, since Drawables may hold references 
to a Context that could be an Activity. Holding a global (indirect) 
reference to an Activity may cause problems later. If these images are 
Bitmap instances, then it should work fine :-)

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

[android-developers] Re: How to resolve outOfMemoryError - Bitmap size exceeds VM budget

2011-09-22 Thread laminina
I had a similar problem to yours, and what i tried is that whenever im
initializing all my elements (after the oncreate) I assign the
background in my activity and not in my XML. (at runtime)

and that's how I fix my outofmemory..
hope this helps

On Sep 22, 8:16 am, joaocruz04 jtcru...@gmail.com wrote:
 Hi all,
 i've been searching the web for a solution but i couldn't find one.
 Most of the solutions are for the case when the screen orientation is
 changed, and then, reimplement onDestroy method. But that's not my
 case.

 I have the case where i have let's say, 10 activities, one leading to
 another.
 Each one has a different background (from a drawable), and each one
 has a image with 700px by 200px (big resolution for big resolution
 devices).

 Both images and background are defined in the respective layout xml.

 The thing is, when reaching activity 7 or 8, it gives me the
 outOfMemory error. I know it's because of the large amount of images.

 Tried to implement onPause and onResume, but then it gives me some
 errors like trying to use a recycled drawable.

 I want to preserve the images, because i may want press back and
 return to the last activity.

 What's the best way to deal with this?

 How can i free an activity from it's background and image when its
 paused, and then when the activity resumes, put the background and
 images back again?

 Thanks in advance,
 João Cruz

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


[android-developers] Re: How to resolve outOfMemoryError - Bitmap size exceeds VM budget

2011-09-22 Thread Streets Of Boston
I assume you have your images shown in an ImageView.

For each of your activities that shows the image in an ImageView:

In the onStart():
  ...
  myBitmap = loadBitmap();
  imageView.setImageBitmap(myBitmap);
  ...

In the onStop():
  ...
  imageView.setImageDrawable(null); // disassociates the bitmap from the 
imageView and it won't access it again.
  myBitmap.recycle();
  myBitmap = null;
  ...

In the loadBitmap():
  Here it is up to you how to load the bitmap, since I don't know where you 
get your images from.


(If you  don't show the images in an ImageView, you'd have to find another 
way to disassociate the bitmap from that other View/control/whatever)


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

[android-developers] Re: How to resolve outOfMemoryError - Bitmap size exceeds VM budget

2011-09-22 Thread lbendlin
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

Re: [android-developers] Re: How to resolve outOfMemoryError - Bitmap size exceeds VM budget

2011-09-22 Thread ashok chakravarthy
You can  try the approach suggested by streets of bosten or you can try
something like below

i). create baseactivity and all remaing activities extends this activity
ii). override onKeydown in the base actiivty
iii).finish the previous activity when you move to next activity. and when
you press the back on the activity based on the index start the previous
activity.

Thanks,
Ashok.

On Fri, Sep 23, 2011 at 6:06 AM, lbendlin l...@bendlin.us wrote:

 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


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