I have been trying to find the cause of weird formatting style inconsistencies for my Views
throughout my application and I think I have narrowed it down with t
In Android sources getApplicationContext()
returns Application object which extends ContextWrapper
, so using getApplicationContext()
you are passing ContextWrapper
subclass, but when you pass this
, you are passing an Activity
object which extends ContextThemeWrapper
so you are passing ContextThemeWrapper
subclass. Now the difference between ContextWrapper
and ContextThemeWrapper
is that ContextWrapper
simply delegates all of its calls to another Context and ContextThemeWrapper
allows you to modify the theme from what is in the wrapped context.
Although, the question was more about why exactly this is happening (as opposed to the cause which was clear), here are also some helpful posts which explain the perils of incorrectly using application context and how to choose a context correctly:
Most importantly from @CommonsWare: "getApplicationContext() is not a complete Context and consequently does not support everything that Activity does."
Awesome post about Context that should clarify everything: