Reputation: 8405
I understand that if I have an instance variable in an activity. Data will be gone if the activity gets killed by the OS to free memory. When does the static variable get destroy. Will the OS kill the application to free memory if application gone to background.
I have an application with a static variable which hosted whole application data. Do I need to save / restore it and where should I do it?
Upvotes: 0
Views: 107
Reputation: 1007584
Will the OS kill the application to free memory if application gone to background.
Not immediately. But, when your app is in the background, its process can be terminated at any point.
Do I need to save / restore it
Yes.
where should I do it?
Generally speaking, you persist the data when it changes. Treat your static fields as a cache, nothing more.
Upvotes: 1