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. AppWidget Picker and ACTION_APPWIDGET_PICK

Hi Guys

Does anyone have idea about ACTION_APPWIDGET_PICK alias
"android.appwidget.action.APPWIDGET_PICK ?
Where exactly this is handled ? Basically i want to pick the app
widget  bypassing picking it from standard list of installed
widgets .


Thanks
Tarun"

-- 

2. Highlight part of the text in a textview object

Here is the more difficult, lower-level way to do this (probably also
has more functionality): 
http://developer.android.com/reference/android/text/Spannable.html

Here is the much easier way to do this: 
http://developer.android.com/reference/android/text/Html.html
... This one is REALLY nice. You can do things like
Html.fromHtml("Whatever I want <b>bold</b>"); .. This allows you to
use basic HTML markup to format your text. I'm not sure how many or
which HTML tags are supported.

-Nick






> 

3. Weird: It appears as if sometimes my Activity will be resumed but previously set instance variables are null

4. Exception in setDrawingCache in Android 1.5?

5. How to Bind data to list?

6. Quick & Easy Question

7. Problem porting Android to iPhone