2

As it stands we need to pass a Context in many places within Android application. I'm wondering how safe it is to use a static variable which refers to the Application class instance in such places? For example, I have a static method in one of my Activities and I can't use this (as Activity) or something because the method is static, so I'm guessing to use the Application.instance reference which is initialized on each application start. Is it ok you think? Thanks a lot.

Eugene
  • 59,186
  • 91
  • 226
  • 333
  • http://stackoverflow.com/questions/7298731/when-to-call-activity-context-or-application-context. also check this http://android-developers.blogspot.in/2009/01/avoiding-memory-leaks.html – Raghunandan May 30 '13 at 08:17

1 Answers1

3

It depends on your method and what you are trying to do with the Context. If you want to get resources like a String or Drawable from your app, then it is save to use the Application Context. But if you want to display a Dialog, then you definitely should use the Activity Context.

As far as I know, for a Toast you can use the Application Context as well.

vRallev
  • 4,982
  • 3
  • 31
  • 34