Consider my application has one activity and I have a static variable in that activity. At first time i initialize the variable , starting a service and exit from the application. At some instance am trying to access the static variable which i initialized before. Sometimes the value is present. but at some times null value is retrieved. plz advise whats going wrong
Thanks in advance.
Once the activity is killed by the SO, all the memory resources are back to the system, so you lose the data in that variable. If the activity goes into background instead, the value will be retained
You cannot rely on a static variable to persist indefinitely. When your application terminates, your statics are gone. If you need to store a value permanently, persist it to a database, filesystem or some other means of storage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With