I often use a static class like a "global" placeholder for values and classes. This could fx. contain the current logged in users class, and other information.
When the app first starts, I make sure all variables are loaded and initialised, in this case fx. the CurrentUser class is loaded and added to the static class.
As its a static class, I more or less rely on it being there always, so I just reference it like "GlobalClass.CurrentUser" from anywhere in the app.
But sometimes, mostly when coming back to the app, I see that the "GlobalClass" has been unloaded and then being loaded again, due to the nature of accessing a static class - but as I rely on the static class to "live" forever inside my app, I only initialise it when the app starts the first time - so now the "GlobalClass" are instantiated again and exists, but it has lost all of its data and settings (as I do not initialise variables, as I do when the app starts the first time)
I first saw this starting to happen on an Xamarin Android app a few months ago, but now I see iOS users facing the same issue.
Any idea what is going on ?
Why are static classes not persisted 100% thru the entire app lifespan ?