Here are reasons why not to use getApplicationContext()
wherever you go:
- It’s not a complete
Context
, supporting everything thatActivity
does. Various things you will try to do with thisContext
will fail, mostly related to the GUI. - It can create memory leaks, if the
Context
fromgetApplicationContext()
holds onto something created by your calls on it that you don’t clean up. With anActivity
, if it holds onto something, once theActivity
gets garbage collected, everything else flushes out too. TheApplication
object remains for the lifetime of your process.
See this table as a guidance for when to use the different types of Context: