Will a static variable live even after closing the application?

Consider that my application has one action, and I have a static variable in this action. First, I initialize the variable, starting the service and exiting the application. In some cases, I try to access a static variable that I initialized earlier. Sometimes meaning is present. but in some cases a null value is returned. plz advises what goes wrong.

Thanks in advance.

+4
source share
3 answers

As soon as the activity is destroyed by SO, all memory resources are returned to the system, so you lose data in this variable. If the action goes to the background, the value will be saved

+5
source

You cannot rely on a static variable that will persist indefinitely. When your application terminates, your statics will disappear. If you need to save the value permanently, save it in the database, file system or other storage media.

+1
source

If you want to store values ​​even after exiting the application, perhaps you should consider using General Settings .

+1
source

All Articles