If any static variables are destroyed, are they all destroyed? This is the code I have in my OnCreate
method:
if (!LoadedData)
{
LoadedData = true;
SaveData = getSharedPreferences(FILENAME, MODE_PRIVATE);
LoadData();
if (MainActivity.ScreenWidth == 0 && MainActivity.ScreenWidthLandscape == 0)
MainActivity.LoadData();
}
The first time my class runs, LoadedData will have the default value of false, causing any values saved to be loaded and stored in the static variables. After the device is rotated, this code will not run because all the values needed are kept in static variables, so it would be inefficient to load them again. The problem is, if some static variables are destroyed, but not all, then my program will likely crash. When static variables are destroyed, will they hold the default values? Eg integer = 0, boolean = false etc.
I have no way to test for static variables being destroyed.
Checking a static variable for one class will tell you if that class has been destroyed or not. That means you can know if the other variables in that class are still ok. It tells you nothing about other static variables in other classes.
If LoadedData
has been destroyed, it will be because nothing is referring to the class that contains it. The class has been finalized and garbage collected. The entire class will be reinitialized when the system loads it again.