Insufficient Memory Error when launching application for second time after calling finish() in main activity..

by Streets Of Boston » Tue, 21 Apr 2009 22:21:19 GMT


Sponsored Links
 Do you statically cache objects?
If your activity is gone/finished, that does not necessarily mean that
your game's process has died. Static references/caches may still be
active.




--~--~---------~--~----~------------~-------~--~----~



Insufficient Memory Error when launching application for second time after calling finish() in main activity..

by quakeboy » Wed, 22 Apr 2009 20:48:38 GMT


 Thnx for replying SOB..
I found I was using all Animation objects like that and I changed it.

Later, still I found it was crashing at one particular line.. It might
be helpful for developers so here it is..

==========BEFORE===============

I set a different background at runtime.. like this.. (Its a 320 x 480
image)
view.setBackgroundResource(R.id.mybgid);

===========NOW==============

Now I removed that line and do this..
Bitmap lastbg = null; (this is on top only)

if (lastbg != null) lastbg.recycle();
Bitmap b = BitmapFactory.DecodeResource(.....as req.....);
BitmapDrawable bd = new BitmapDrawable(b);
view.setBackgroundDrawable(bd);



Now the final result..
My application still crashes, but the crash frequency has reduced to
25%

Now I am sorry, but Some Android Engineers from Google were stubborn
telling that BitmapFactory and settings image resources never leak
memory..

But in my personal experience, I found When I load sprites for each
level, initially after the level is over, I did not recycle() and then
it crashed frequently.. later I did that at the end of each level and
crash frequency dropped a lottt..

I even tried System.gc() in lot of places... Guys have to understand..
we use JAVA !!! not C++... we dont have delete operators.. or free
()... how the, am I supposed clear memory... Please GC better for
images..

Moreover through my application I have a lot of imageview for which I
change their Image on touch event ACTION_DOWN like this...

imgbtn.setImageResource(R.drawable.mouse_down_sprite);

Does all this leak little amounts of memory ??
Can someone tell me how to change this discussions subject ?





--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Insufficient Memory Error when launching application for second time after calling finish() in main activity..

by quakeboy » Wed, 29 Apr 2009 20:51:58 GMT


 Hey i found a lot of help with this article
 http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html 

Hope it helps others too





--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Tanya Google talk

Lagi iseng pingin nyobain google talk di spica tapi kok secara default dia
pakai email A yah, bagaimana cara sign out dan ganti ke account email yang
lain? Saya udah coba utak atik tapi ngga nemu cara ganti account lain. Mohon
bantuannya

Trims,
Alex

-- 
"Indonesian Android Community [id-android]" 

2. Not using a WakeLock so why does the device stay awake?

Use this to see what wake locks are being held in user space:

adb shell dumpsys power

Note that the device never goes to sleep while plugged in to USB.  Also the
system will never hold a wake lock for you just because you have an activity
or service running.  You can have it do so for you in an activity via
FLAG_KEEP_SCREEN_ON in a window, and the alarm manager will temporarily hold
one for you while sending an alarm broadcast to a broadcast receiver.








> 

3. is there a way to create a menu from scratch?

4. Not using a WakeLock so why does the device stay awake?

5. Source code fro Genie Widget

6. ScrollView cycle?

7. Selling outside the Android Market--> Use Google Checkout to sell direct from website??? SlideMe.Org??