kajman
kajman

Reputation: 1076

Save state when system closes application on low memory

is it possible to intercept the event of system closing my application on low memory? I know there is a method "onLowMemory" but it doesn't mean that my application will be closed after it is invoked.

My problem is that I'm co-developing an app that uses a lot of static data (which I know should be avoided, but that's not my decision and at this point it's almost impossible to change this fact). If I press home and don't get back to this application for eg. 10 hours it would probably force close when I do because the static data isn't there anymore (app got killed by the system).

Is it possible to know when the app is about to get killed by the system? I would store the static data somewhere to get it later then, when I recreate my app. What are possible solutions?

Maybe, if hooking to such an event is impossible, I could make a service that saves this state every few minutes, so when app gets killed I would probably have the latest static data?

Did you encounter this problem? What are your solutions/suggestions?

Upvotes: 0

Views: 892

Answers (1)

Tim
Tim

Reputation: 35943

Does your app do anything with this static data in the background? You could just save everything in onPause(). Once onPause has been called your app is killable at any time without any further callbacks, so if something needs to be saved, onPause is the place to do it.

Upvotes: 1

Related Questions