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. Customize filter with MultiAutoCompleteTextView

Currently I'm using the default filter but I would like to be able to
make it so I can ignore some letters at the beginning of the strings
in the adapter. I've had a look at the public methods available on
MultiAutoCompleteTextView but can't find anything on how to pass my
own filter to it. Any idea how to do this?
--~--~---------~--~----~------------~-------~--~----~

2. draw text as big as possible inside a rectangle

Is there any convenient method to draw a string (custom true type
font)
as big is possible inside a supplied rectangle or to calculate the
font
size of a paint object based on a string and some rectangle
dimensions.

Thanks in advance
Michael
--~--~---------~--~----~------------~-------~--~----~

3. Bytecode assembler

4. Number of Bluetooth Connections

5. Webview questions

6. Change TextView text in code

7. How to enable DUN in G1 phone?