27.03.2011 20:17, Mark Murphy пишет:
Singletons, manager, or utility classes should not be caching a
Context.

They can and should if needed or wanted. However ...

  At most, they should be caching an Application, to prevent
people from accidentally caching short-lived Contexts (e.g., Activity,
Service).

... I'd further qualify that as "... a cached Context (if needed) should be an Application object reference, rather than a local, short-lived Context".

I used to use lines like TreKing's "Never use
getApplicationContext()", but I've tried to be a tad more nuanced in
recent months.

Good.

Broad statements like that always remind me that "the difference between theory and practice is that, in theory, there is no difference".

That being said, there is no question in my mind that,
in a support board like this, getApplicationContext() is a major code
smell. Most times, it is not needed, and can sometimes give erroneous
results.

Right. Let's just not throw the baby out with the bath water :)

--
Kostya Vasilyev -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to