Why to extend an Application
class?
What is in it for me?
Why would you do that?
I read that it can be used to declare global variables, is that all or are there any other applications?
Why to extend an Application
class?
What is in it for me?
Why would you do that?
I read that it can be used to declare global variables, is that all or are there any other applications?
I see that this question is missing an answer. I extend
Application
because I use Bill Pugh Singleton implementation (see reference) and some of my singletons need context. TheApplication
class looks like this:And the singletons look like this:
This way I don't need to have a context every time I'm using a singleton and get lazy synchronized initialization with minimal amount of code.
Tip: updating Android Studio singleton template saves a lot of time.