when I declare and initialize a variable as static in my main activity and the activity gets destroyed. Can I still access the content of the variable?
For example t
I'm actually surprised that nobody was able to find a reference. It's right there on Wikipedia:
...a static variable is a variable that has been allocated "statically", meaning that its lifetime (or "extent") is the entire run of the program. This is in contrast to shorter-lived automatic variables, whose storage is stack allocated and deallocated on the call stack; and in contrast to objects, whose storage is dynamically allocated and deallocated in heap memory.
This definition is for general programming languages. But it can be used as a reference to Android
. However, in object-oriented programming languages:
In object-oriented programming, there is also the concept of a static member variable, which is a "class variable" of a statically defined class, i.e., a member variable of a given class which is shared across all instances (objects), and is accessible as a member variable of these objects. A class variable of a dynamically defined class, in languages where classes can be defined at run time, is allocated when the class is defined and is not static.
Meaning that in Android, where Java, is used static variables have a lifetime equal to the lifetime of the app, or the instance that is using it, if that static variable is not created at runtime.