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. Failed to find provider info for com.google.settings

Hi!

I was looking in the forum but couldnt find any useful information
regarding my error. I just wanted to implement the map-example /
tutorial but if i start the map-activity, i get..

Failed to find provider info for com.google.settings

07-27 16:55:24.917: ERROR/ActivityThread(854): Failed to find provider
info for com.google.settings
07-27 16:55:25.077: DEBUG/AndroidRuntime(854): Shutting down VM
07-27 16:55:25.087: WARN/dalvikvm(854): threadid=3: thread exiting
with uncaught exception (group=0x4000fe70)
07-27 16:55:25.087: ERROR/AndroidRuntime(854): Uncaught handler:
thread main exiting due to uncaught exception
07-27 16:55:25.126: ERROR/AndroidRuntime(854):
java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.airwriting.mobile.android/
com.airwriting.mobile.android.activity.helper.map.Map}:
java.lang.NullPointerException
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2268)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2284)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
android.os.Handler.dispatchMessage(Handler.java:99)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
android.os.Looper.loop(Looper.java:123)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
android.app.ActivityThread.main(ActivityThread.java:3948)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
java.lang.reflect.Method.invokeNative(Native Method)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
java.lang.reflect.Method.invoke(Method.java:521)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
dalvik.system.NativeStart.main(Native Method)
07-27 16:55:25.126: ERROR/AndroidRuntime(854): Caused by:
java.lang.NullPointerException
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
com.airwriting.mobile.android.activity.helper.map.Map.onCreate
(Map.java:19)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1123)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2231)
07-27 16:55:25.126: ERROR/AndroidRuntime(854):     ... 11 more

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

2. Android on Motorola A810?

Hello all,

I have a Motorola A810 that is based on OMAP730/850..
There are a couple of videos on A810s that have been ported to
Android..

Could you please guide me on the steps involved in a generic port?
I've looked for the FAQs talked about in the group's introduction but
haven't been able to find them.

--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. Using custom _init and _fini on Android ARM

4. dirent64 is missing in bionic/libc/kernel/common/linux/dirent.

5. MPEG2 TS + HTTP Live Streaming Support on Android

6. the mediaplayer with mediacontroller issue

7. How to convert XML into java code ?