简体   繁体   中英

My android service onDestroy method is not being called. Could it be because of low ram?

I have a galaxy vibrant. I installed ICS rom on it a while ago. I noticed a video capturing program I used to use on 2.2 now suddenly quits without notification while I am capturing video. I then went on to learn that ICS uses a lot of memory.

I am now working on an app that creates an array of objects through service intents. The service is a sticky service. So, to my understanding, it sticks around for as long as it can. On my onDestroy method, I serialize my array of objects to a file so that when my service starts up again, the array is loaded (if the file exists). So I test my app, everything runs good, then I quit the activity (intent should still be running in background). Then I run the ICS internet browser and I get a Force Close from my App.

Is it possible that my system kills my service and ondestroy is never called?

As with an activity, the onDestroy method is called when the service is about to be terminated. Android will terminate a service when there are no more clients starting or bound to it. As with activities, Android may also terminate a service when memory is getting low. If that happens, Android will attempt to restart the service when the memory pressure passes, so if your service needs to store persistent information for that restart, it's best to do so in the onStart method.

Could it be because of low ram?

as i mention earlier yeah.

Source : OReilly.Android.Application.Development

When your programm is about to being closed, you should call yourActivity.finish() which will call onDestroy().

onDestroy is not always called when applications are finished by Android system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM