In the past I've subclassed Application
to maintain an active database connection for the application. However, according to this SO answer Application
runs in the UI thread, which makes me think I should definitely not use it for database access. Furthermore, according to the Xamarin Application
docs (and those of Android proper):
There is normally no need to subclass Application. In most situation, static singletons can provide the same functionality in a more modular way. If your singleton needs a global context (for example to register broadcast receivers), the function to retrieve it can be given a
Context
which internally usesContext.ApplicationContext
when first constructing the singleton.
I think I understand the Context
to be something I can use to maintain some sort of static access to application resources, but there are no examples in the docs and I've not encountered this situation before. Would anyone be able to explain the above note and relate how they have used Context
to maintain application resources (unless I'm completely missing the point)? Links to or direct examples would be appreciated.