Both you (@Matthias) and Mark Murphy (@CommonsWare) are correct in what you say, but the gist seems lost. (The use of volatile
is correct and classes are not unloaded.)
The crux of the question is where initialize
is called from.
Here is what I think is happening:
- You are calling initialize from an
Activity
* - Android needs more memory, kills the whole
Process
- Android restarts the
Application
and the topActivity
- You call
getInstance
which will returnnull
, asinitialize
was not called
Correct me if I’m wrong.
Update:
My assumption – that initialize
is called from an Activity
* – seems to have been wrong in this case. However, I’ll leave this answer up because that scenario is a common source of bugs.