How to handle OutofMemoryError in a service?

by doug » Tue, 10 Aug 2010 07:34:54 GMT


Sponsored Links
 Hello,

If my service encounters an OutofMemoryError when creating new
objects, what can I do to tell Android to restart my service later?  I
thought about Alarm but then I can't create a pending intent in the
OutofMemoryError situation...

Thanks,
doug

--



How to handle OutofMemoryError in a service?

by Jenus Dong » Tue, 10 Aug 2010 09:15:03 GMT


 Service is bound to acrtivity, this kind of service you can control. So if
service has encounted an OutofMemoryError, the OS could restart your
activity, you can restart your service in the activity, eg, OnCreate,
OnRestart.




>


Sponsored Links


How to handle OutofMemoryError in a service?

by Soumya » Tue, 10 Aug 2010 12:48:52 GMT


 I would investigate the "root cause" of out of memory error instead of
finding a way to restart your service/activity.





--



How to handle OutofMemoryError in a service?

by Kostya Vasilyev » Tue, 10 Aug 2010 15:14:00 GMT


 Doug,

You can set an alarm before allocating objects that result in the out of 
memory condition.


But this is really just a band-aid - IMHO, you should optimize your 
service's memory usage.


-- Kostya

10.08.2010 3:34, doug :
Hello, If my service encounters an OutofMemoryError when creating new objects, what can I do to tell Android to restart my service later? I thought about Alarm but then I can't create a pending intent in the OutofMemoryError situation... Thanks, doug
-- Kostya Vasilev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com --



How to handle OutofMemoryError in a service?

by doug » Wed, 11 Aug 2010 01:55:34 GMT


 Thanks for the suggestions.  What I was looking for is a defensive
programming technique to guard my service against memory exhaustion
caused by other services/activities running on the device.  The SDK
has this to say about a service process:

"...so the system keeps them running unless there's not enough memory
to retain them along with all foreground and visible processes".

But are you implying that OutofMemoryError will not occur *before* a
service is killed in a low memory situation?  In other words, an
OutofMemoryError  will occur *only* when my own service eats up all
the 16 MB default heap size.  Then I don't need to worry about another
service/activity squeezing the 16MB heap size.  Is that true?

doug

--



How to handle OutofMemoryError in a service?

by doug » Wed, 11 Aug 2010 03:51:01 GMT


 Thanks!  That answered my question.

doug

--



Other Threads

1. Hadith Arbain 10 Bahasa

Di pasar pagi atau malam bro.. klo boleh japri doang apknya bro...

Best Regard

Arisandy
Sent from Smartphone
HTC "Android" Hero
Roufianos 1.2
App2SD

YM     : arisandy_pratama

Gtalk : ari.sandy.pratama.hero

Twitter : @abinya yazid




maaf cross posting,
cuma mau introducing aplikasi Hadith Arbain v.1.0

   1. berbeda dengan aplikasi yang mengandung tulisan arab lainnya yang
   menggunakan gambar utuk tulisan arab (android belum support arabic
   localisation),aplikasi ini tidak menggunakan gambar, jadi ukuran aplikasi
   (apk) lebih kecil.
   2. downloadable beautiful audio recitation
   3. pilihan terjemah hadits dalam 9 bahasa
   4. simple yet beautiful UI :)


download di market:

video demo (youtube): http://www.youtube.com/watch?v=ayo97N5i4MM


silahkan beri komentar, dan jangan lupa laporkan error :)
dan selamat menyambut Ramadhan 1431 H {43 hari lagi}
-- 
Best Regards,
hakim

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

2. Ijin bergabung

Pagi, saya andi prasetya dari malang, ijin bergbung di milis ini.

Kepada moderator makasih sudah approve.

sent from Robot Ijo Xperia X10 ~[]~

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

3. Kernel requirement for Android 2.2

4. Unlock KeyGuard

5. Froyo still breaks compatibility

6. Mod: Mohon Masukan dari Developer Android

7. X10i Latest Update dari S