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. Does Android have a LinkButton. Basically like text but you click on it?

You could maybe put a ImageButton over a TextView and set the button's
image to a state list drawable with transparent colors for the various
states.  That way you would get a visual indication when your text is
focused/clicked, etc.  You *MAY* be able to simpy make a TextView
focusable, but I am not sure how you would change the focus/clicked
colors of the text, which is why my previous suggestion.




-- 

2. Radio Waves

Hi guys,

Is possible to issue radio waves by andoid?

I wanted to issue radio waves through an app, but I didn't know what
to search to start my tries.

I'm so sorry because my English is rain and I already thank you for
helping me.

[]'s

-- 

3. Language correction!!! (en-ZA)

4. List

5. New to Ant build and I think my project setup has problems

6. AlertDialog

7. Ho to write files to internal or external cache directory?